Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

URL format and Form method=get (ASP)

Posted on 2013-05-22
6
Medium Priority
?
537 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
  • 2
  • 2
  • 2
6 Comments
 
LVL 84

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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 84

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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Loops Section Overview
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

773 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