The direct use of Response.Redirect ("default.aspx") of course the validation failed, because you did not establish an authentication ticket. FormsAuthentication.RedirectFromLoginPage method, will automatically complete a lot of functions. such as the completion of the generation of authentication ticket, write back to the client, browser redirection and so on a series of actions. Of course, the completion of these functions is not only the FormsAuthentication.RedirectFromLoginPage method to do, on the other hand, if you need to have the role of information validation can only use other methods.
We can use the manual to add the authentication ticket
1.
Copy Code code as follows:
FormsAuthenticationTicket Ticket = new FormsAuthenticationTicket (1, "Coffee", DateTime.Now, DateTime.Now.AddMinutes ( , False,userroles, "/");
Note: Userroles does not know to write ""
2. Encryption serialization
Copy Code code as follows:
String hashticket = Formsauthentication.encrypt (Ticket);
3. Generate cookies
Copy Code code as follows:
HttpCookie Usercookie = new HttpCookie (Formsauthentication.formscookiename, Hashticket);
Cookie. Domain = ". Jb51.net";
4. Authentication ticket cookie output to client
Copy Code code as follows:
RESPONSE.COOKIES.ADD (Usercookie)
5. redirect
Copy Code code as follows:
Response.Redirect (context.request["ReturnUrl"]);