Solved

URL format and Form method=get (ASP)

Posted on 2013-05-22
6
510 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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 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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

860 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