Solved

URL format and Form method=get (ASP)

Posted on 2013-05-22
6
488 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 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 30

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 30

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

867 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now