After form authentication is passed, only the formsauthentication.redirectfromloginpage_ practical skills can be used

Source: Internet
Author: User
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"]);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.