Form Data Not Posting While Using URL Rewrite - asp.net

OK. Where to start....
I have a website. It is running on an IIS server using classic asp. I have forms on that website.
The forms were working fine until I decided to add some url rewrite rules to my web.config file to redirect nice looking urls.
After doing that, the form on my website does not post the data. It is going to the correct address, but nothing is passing to the page that is suppose to do the processing. On the page that I am processing if I do this:
For each FieldName in Request.Form
Response.write FieldName & " = " & Request.Form(FieldName) & "<br>"
Next
I get absolutely nothing. No form field names or values.
What do I need to add to the web.config file so that the data will post? And... more importantly... Where do I need to add it at in my web.config file?
Here is a text copy of my web.config file http://elvis-is-alive.com/webconfig.txt

Your web.config contains action=redirect.
A redirect always results redirect header being sent to the browser. This changes the URL in the browser address bar, and the browser then issues an HTTP GET for the new address. With an HTTP GET, no form/post data are ever sent; all arguments are assumed to be in the URL querystring.
If you'd like to avoid the redirect and use a true rewrite, change your web.config to use action=rewrite. Using this method, no redirect header is sent back to the browser, the browser address bar never changes, and IIS simply redirects the current request stream to a different location.
Something tells me that's not what you want-- you want the address bar in the browser to change and you want the form/post data to be preserved. This is not possible unless you do something very unusual, e.g. render a temporary interstitial page containing the original form/post request with an action pointing at the new URL. I don't recommend doing this.
Why not just change the form action in the original page's HTML?

Related

Webalizer not picking up on server-side redirects

I'm using Webalizer on an intranet, and I want statistics for clicks on outbound links. I set up the links to point to a simple ASP redirection page -
each link resembles "redirect.asp?url=http://outsidesite.com". But Webalizer is not tracking the redirections. Is there a setting in the Webalizer config file that needs to be changed? Or do I need to set up the redirection differently?
I found a solution - I used a META refresh in my ASP page instead of a server-side redirect. The server-side code puts the query string's URL in the refresh's CONTENT value.

How to set custom header and redirect to specific location

I am trying to set a custom header variable after doing a lookup in SQL Server and then redirect the user while still having access to the variable. I have tried:
Response.Addheader "custvar", customvariable
Response.Redirect("http://example.com")
But when I get to example.com the header is not present. Is there another way to do this? I am using IIS and have tried the simple ASP above so far.
I don't think it is possible to do it with header.
What Response.Redirect effectively does is it sends the 302 result (Found or Moved Temporarily) to a browser. Then browser makes another call to the address which was provided in 302 result. This means that you are creating a response header for 302 result, but this header has no way to be used in subsequent result to example.com.
If you want to pass some information between requests and request is made to the same site you could set a cookie and it will be sent during your redirect. If you control the site where you redirect to you can also use query string to pass the required parameters. Of course you should not add sensitive information to either cookie or query string.
I agree with #dotnetom. I use response.redirects with variables passed in query string very successfully throughout my application to achieve this result along with variable i wish to pass. Non sensitive data caveat of course also.
Add the custom header as per instructed here
adding custom header with classic asp
and then add the redirect manually without the re-direct
eg.
Response.Addheader "custvar", customvariable
Response.Status="301 Moved Permanently"
Response.AddHeader "Location", "http://www.thenewpage.com"

How to remove query string or how to maintain constant URL using URL rewrite

How to maintain constant URL?
For example:
http:// test23232 /temp/temp.aspx?a=1&b=1
a,b,query string parameter name get differ dynamically page to page(want to use those parameter but not dispaly for users)
While redirecting ,whatever the value present after ? should be removed and final URL displayed to users:
http:// test23232 /temp/temp.aspx or http:// test23232 /temp
Or any constant url post login mentioned throughout entire application.
I can acheive this by iframe, but how can I do by doing web.config through rule or global ascx.
or
whatever page redirect
http : //localhost /test/security / login.aspx
http : //localhost /test/security / main.aspx
http : //localhost /test/security / details.aspx
I want to show to browser as
http :// localhost / reap/ security /
Is it possible?
Use Session to store the values of a and b and keep the url simple.
You can send the necessary parameter using post method instead of get method.
More secure way of passing them is to store them into session variable.
that might make it more "secure" since then the client cannot change the variables by editing the source.
It will depends on how you really want to do.
The session parameters will keep on changing dynamically for every request.We can go for cookies.
Yet this link might be useful for url rewriting

ASP.NET - Razor. Rewrite URL on the fly

Is it possible to rewrite URL on the fly, only when a part of the server code has already been processed for the "raw" URL and it becomes clear the parameters must not be revealed to the user? Like, I want to proccess all the GET parameters in my page code on the server and create a tracking record in the database, then serve the user the page but change URL to parameterless in the browser.
I guess all the web.config referred module techniques won't work as they offer URL rewriting before request is passed to the page code on the server. But it comes in my case that I receive an ugly URL from google adwords clicks and I do like it tracked 'as is' in my database, and I do certainly not like it show to user in her brower's bar.
At the same time I would like to keep URL unchanged without applying the URL rewrite most of the time unless some particular parameter shows up in it (like ref=adwords) so that any paramter written by hand or posted back would be displayed in the address bar.
Is it possible to do so by any means?
Have you considered writing an ActionFilter that would (if your controller or method is decorated with it) intersect your initial request, do all the necessary processiong and then redirect back to the requested page only indicating, that processing has been done?
This would be my first thought.

redirecting postdata

I've recently upgraded a page on our server from classic asp to asp.net
The page recieves postdata and saves it to a file. The page is used by many of our clients and the url (to the asp page) is hard coded into their software. This means that i cannot simply swap the old page out for the new one.
I'm trying to find a way to redirect clients from the old url to the new one.
I know you can do a simple redirect using IIS, but this does not cause the postdata to be redirected.
I've tried setting the file to a 307 temporary redirect, this works when the data is in the formdata but other post requests such as ones using the msxml library do not work.
Basically i need to find a way in IIS to forward a post request from one page to another without losing any of the body.
If the two pages are within the same application, you can use Server.Transfer. This just shifts the processing from the old page to the new one, and maintains all of the request data.
The best way i found was to use the temporary redirect code in IIS, although this didn't work for postdata originating from the msxml library. In the end i had to write a COM library in .NET to do the hard work using the system.encoding libraries and then reference the COM library in asp
You can always program (in asp.old) a loop that goes through all the form-data and insert a record with all the values in the database. You then redirect the user to your aspx-page with the id of the row in the database as a querystring parameter. Be careful if the form-data is sensitive, to apply some sort of security to make sure users wont "steal" others data by changing the querystring.
Redirect Reference (IIS 6.0)
http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/41c238b2-1188-488f-bf2d-464383b1bb08.mspx?mfr=true

Resources