Solved

URL format and Form method=get (ASP)

Posted on 2013-05-22
6
480 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 82

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 82

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
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/…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video discusses moving either the default database or any database to a new volume.

707 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

18 Experts available now in Live!

Get 1:1 Help Now