We know that in asp.net mvc, you jump from one action to another, usually with a series of methods that start with "Redirect."
- Redirect
- Redirecttoaction
- Redirecttoroute
Sort of.
However, when you use the Redirect series method to jump, the default is to use the Get method, that is, if your jump request with parameters, then all of these parameters will be exposed to the URL after the jump, increased insecurity (especially if the parameters include passwords, keys, etc. sensitive data)
So it comes to the idea of using the Post method to pass data so that at least a typical visitor cannot get sensitive information from the URL. But with a closer look at MSDN and StackOverflow, the answer is "the redirect method does not support post."
Fortunately, StackOverflow found an answer to the point I, but give me some inspiration. Direct post is not, then the indirect post, first get a page through a getting method, and then on this page for the intermediary to post the data to the real request to process the page.
A sample code is given below. In this sample code, there are two pages login and afterlogin that require you to enter a username and password in login and then jump to afterlogin and carry a list of the data defined by Userappmodel
public class Userappmodel
{public
string UserId {get; set;}
public string ClientId {get; set;}
public string Redirecturi {get; set;}
}
This information is obtained when the login page is loaded using the Get method.
Public ActionResult Login (string client_id, String Redirect_uri)
{
HttpCookie cookie = new HttpCookie ("app"); c3/> cookie["client_id"] = client_id;
cookie["Redirect_uri"] = Redirect_uri;
RESPONSE.COOKIES.ADD (cookie);
return View ();
}
The interface design is omitted, nothing more than two text boxes and a Submit button.
Then there is a HttpPost method for login to receive login data and construct Userappmodel data to be sent to the new Afterlogin page.
[HttpPost] public actionresult Login (Usermodel model) { if (modelstate.isvalid) {&
nbsp; HttpCookie cookie = request.cookies["app"]; if (cookie!= null) { if (model. UserId = = "AAA" && model. Password = = "AAA") {
Userappmodel Newmodel = new Userappmodel (); Newmodel.userid = Model.
UserId; Newmodel.clientid =
cookie["client_id"]; NEWMODel.
Redirecturi = cookie["Redirect_uri"]; tempdata["model"] =
Newmodel; return
Redirecttoaction ("Afterlogin", "Home"); } viewbag.message = "Login error!
Invalid user ID or password. ";
} } return View (); }
Afterlogin requires two methods, a get way, a post way, through the page to call the Post method of the page, the implementation of the use of post redirection
//POST:/home/afterlogin
[Acceptverbs (httpverbs.post)] public
actionresult Afterlogin (Userappmodel Model)
{
viewdata["model"] = model;
return View (model);
}
[Acceptverbs (Httpverbs.get)]
Public ActionResult Afterlogin ()
{return
afterlogin (tempdata["model" as Userappmodel);
}
Conclusion: The redirect Series method does not support post, but it can realize post way redirection through indirect procedure.