After the form authentication is passed, only FormsAuthentication. RedirectFromLoginPage can be used

Source: Internet
Author: User

If Response. Redirect ("default. aspx") is used directly, the authentication fails because you have not created an authentication ticket. The FormsAuthentication. RedirectFromLoginPage method automatically completes many functions. Such as generating authentication tickets, writing back to the client, browser redirection, and other actions. Of course, only the FormsAuthentication. RedirectFromLoginPage method can complete these functions. On the contrary, if you need to verify the role information, you can only use other methods.
You can manually add an authentication ticket
1.
 Copy codeThe Code is as follows:
FormsAuthenticationTicket Ticket = new FormsAuthenticationTicket (1, "coffee", DateTime. Now, DateTime. Now. AddMinutes (20), false, UserRoles ,"/");

NOTE: If UserRoles does not know, write ""
2. Encrypted serialization
Copy codeThe Code is as follows:
String HashTicket = FormsAuthentication. Encrypt (Ticket );

3. Generate cookie
Copy codeThe Code is as follows:
HttpCookie UserCookie = new HttpCookie (FormsAuthentication. FormsCookieName, HashTicket );
Cookie. Domain = ".jb51.net ";

4. the authentication ticket Cookie is output to the client.
Copy codeThe Code is as follows:
Response. Cookies. Add (UserCookie)

5. Redirection
Copy codeThe Code is as follows:
Response. Redirect (Context. Request ["ReturnUrl"]);

Related Article

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.