How to Retain Request.Form data
This is regarding forwarding POST variables properly in ASP.Net
To force all connections use the https protocol rather than http, I inserted the following code in Global.asax
If Not Request.IsSecureConnection Then
Response.Redirect("https://" & Request.ServerVariables("HTTP_HOST") + Request.RawUrl)
End If
This was working fine until I encountered a form which is submitted using POST, and using the above method is breaking the form re开发者_运维百科trieval process.
Eg: the webpage is http://abc.com/page1.aspx (this page accepts only POST form data). now with forcing the application to redirect to https, the page is correctly getting redirected to https://abc.com/page1.aspx, however, all the form data is lost in the process.
Is there a way I can store and forward the Request.Form data??
That's pretty much what the HTTP 307 status code is for. You may want to consider redirecting them with an HTTP 307 status instead of 302.
An HTTP 307 means redirect, and re-submit POSTed data:
In this occasion, the request should be repeated with another URI, but future requests can still use the original URI.[2] In contrast to 303, the request method should not be changed when reissuing the original request. For instance, a POST request must be repeated using another POST request Reference
There is no super easy way to do it in ASP.NET, but it isn't hard either. For example:
Response.StatusCode = 307;
Response.Status = "307 Temporary Redirect";
Response.AddHeader("Location","http://www.new-url.com");
Alternatively, you could use Server.Transfer(string)
as well. Phil Haack gives an explanation of that here. That may be a simpler option for you.
Sub Session_OnStart
If UCase(Request.ServerVariables("HTTPS")) = "OFF" Then
sRedirect = "https://" & Request.ServerVariables("SERVER_NAME") & Request.ServerVariables("PATH_INFO") & "?" & Request.Querystring
Response.Redirect sRedirect
End if
END Sub
Add the above to your global.asa or global.asax.
精彩评论