Log on with a cookie, save the cookie, and read the cookie (C #)

Source: Internet
Author: User
Tags set cookie
1 Login
2
3 // Set product information here
4 String Productinfo = " FTP " ;
5 // Set User Information
6 String Userinfo = Ftppanelsdr [ " Username " ]. Tostring (). Trim () + " | " + Ftppanelsdr [ " Ftpid " ]. Tostring (). Trim ();
7
8 Formsauthenticationticket ticket =   Null ;
9
10 Ticket =   New Formsauthenticationticket ( 1 , Userinfo, datetime. Now, datetime. Now. addhours ( 50 ), False , Productinfo, " / " );
11 // Encrypted serialization verification ticket as a string
12 String Hashticket = Formsauthentication. Encrypt (ticket );
13 // Generate client cookies
14 Httpcookie usercookie =   New Httpcookie (formsauthentication. formscookiename, hashticket );
15 // Usercookie. expires = datetime. Now. addhours (8760 );
16
17 // Set cookie as a browser Process
18 Context. response. Cookies. Add (usercookie );
19 // Redirect to the initial page of user application
20 If (Context. request [ " Returnurl " ] ! = Null )
21 {
22Context. response. Redirect (context. request ["Returnurl"]);
23}
24 Else
25 {
26 // Set the page to jump
27 Context. response. Redirect ( " FTP/ftp. aspx " );
28 }
29
30 Obtain the value in the cookie.
31
32 // Obtain user information
33 /**/ ///   <Summary>
34 /// <-- 0 -- User ID/1 -- User Name/2 -- Role ID/3 -- level ID/4 -- level name -->
35 /// 0 -- username/1--ftpid
36 ///   </Summary>
37 ///   <Returns> </returns>
38 Public   Static   String [] Getuserinfo ()
39 {
40ReturnHttpcontext. Current. User. Identity. Name. Split ('|');
41}
42
43 // Get User Role
44 /**/ ///   <Summary>
45 /// Get User Role
46 ///   </Summary>
47 ///   <Returns> </returns>
48 Public   Static   String Getuserrole ()
49 {
50 Formsidentity ID = (Formsidentity) httpcontext. Current. User. identity;
51 // Get authentication ticket
52 Formsauthenticationticket ticket = Id. ticket;
53 // Set User Roles
54 Return Ticket. userdata;
55 }
56

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.