Solved

URL format and Form method=get (ASP)

Posted on 2013-05-22
6
515 Views
Last Modified: 2013-08-07
I have configured my IIS7 web server to read URI that looks like

media/123/999/

(Read by server as media/?i=123&p=999)

Now the problem is my old ASP pages use form method=get to relay URL variables... so when the user submits the web form the URL goes back to the old format.

What is the best way to use new URL format instead of the old format in the form submit?

Thanks!
0
Comment
Question by:intoxicated_curveball
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39189115
I don't believe you can, that's part of the HTML and HTTP standards.  You would have to rewrite every browser in existence to make that happen.  You may be able to re-write it on the server but every submit form in the world that uses 'get' is going to do that.  The other alternative is to convert the forms to use 'post' which does not show in the URL.
0
 
LVL 18

Expert Comment

by:nap0leon
ID: 39195249
Put a snippet at the top of each page that detects the presence of URL parameters and, if present, reconstructs the URL the way you want it to appear, then do a redirect to the newly constructed URL.

Didn't say it's elegant or efficient, but it answers the question.
Instead of writing the new URL to the page, you could response.redirect the user.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
	<title>Q_28136318.asp</title>
</head>

<body>
<%
Dim newURL
If len(Request.QueryString) > 0 Then
	i = Request.QueryString("i")
	p = Request.QueryString("p")
	SSL = Request.Servervariables("HTTPS")
	If SSL="ON" Then
		newURL = "https://"
	Else
		newURL = "http://"
	End If
	newURL = newURL & Request.ServerVariables("SERVER_NAME") & "" & Request.Servervariables("URL") & "/" & i & "/" & p
End If
%>

<%=newURL%>
</body>
</html>

Open in new window

0
 
LVL 31

Expert Comment

by:Wayne Barron
ID: 39236393
It all really depends on how you have your forms set up.
The <form method="post" action="?Type=Site&amp;id=1">

Just tested it, and it works as expected.

Or am I missing something here?

Carrzkiss
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39236411
I think he wants his forms that use GET to have 'pretty URLs' like he shows above instead of the details that are normally shown.  He wants his form submit URL to look pretty like "media/123/999/" instead of "media/?i=123&p=999".  While he has made the server read the short form, I do not think you can make a form send the short form using the variables in the form.
0
 
LVL 31

Expert Comment

by:Wayne Barron
ID: 39236446
OK, thanks for clearing that up Dave..
Yea, I do not have any idea on how to do that.

Good Luck  intoxicated_curveball
Carrzkiss
0
 
LVL 18

Accepted Solution

by:
nap0leon earned 500 total points
ID: 39237706
think he wants his forms that use GET to have 'pretty URLs' like he shows above instead of the details that are normally shown.  He wants his form submit URL to look pretty like "media/123/999/" instead of "media/?i=123&p=999".

For adjusting the forms to send the "pretty" URLs, have the submit button create the new URL using the form's values.  But you don't really need to submit the form at all... you just redirect the user to the new URL.

The example below uses the form's "action" even though it really doesn't need to.
(Unless he want a form to "POST" to the newly constructed URL (the values would be available as both Request.Form and from the URL parting).

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
	<title>Q_28136318_b</title>
<script type="text/javascript">
function validateForm(){
	var i = myForm.i.value;
	var p = myForm.p.value;
	if (i.length > 0 && p.length > 0) {
		var newURL = '/media/'+i+'/'+p
		document.getElementById('myForm').action=newURL;
		alert('faking a form submit by sendign the user to \n'+document.getElementById('myForm').action);
		/* 
		window.location = document.getElementById('myForm').action;
		*/
	} else {
		alert ('form failed validation');
	}
}
</script>
</head>

<body>
<form name="myForm" id="myForm" method="POST" action="">
	<input type="text" name="i" id="i" value=""><br/>
	<input type="text" name="p" id="p" value=""><br/>
	<a href="javascript:void(0);" onclick="validateForm(this);">Submit Form</a>
</form>
</body>
</html>

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How should I architect a .NET "Interface" to accommodate database requests + database responses? 7 54
Debugging Html 8 31
Session on Html 8 38
Two decimal 5 25
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question