Mvc4 implement cross-domain Cokkie sharing.

Source: Internet
Author: User

Search on the Internet a lot, according to the code above found that the normal sharing. Our site is the use of IIS7

After some time study. Realized,. The code is shared, first C # code

      <summary>////After successful login, set cookies///</summary>//<param name= "entity" >< /param> public void Saveuserformscookie (Loginuser entity, bool Isrememberme = false) {var use  Rdate = Serializationhelper.jsonserialize (entity);            Serializes the object var cookietime = DateTime.Now;            var cookieexpiration = cookietime.addminutes (FormsAuthentication.Timeout.TotalMinutes);            if (isrememberme) {cookieexpiration = Cookietime.addyears (1); } var ticket = new FormsAuthenticationTicket (1, entity.            Username, Cookietime, Cookieexpiration, False, userdate);            var hash = Formsauthentication.encrypt (ticket); var cookie = new HttpCookie (Formsauthentication.formscookiename, hash) {Expires = Cookieexpirat       Ion, Domain = formsauthentication.cookiedomain, Path = Formsauthentication.formscookiepath     };        HTTPCONTEXT.CURRENT.RESPONSE.COOKIES.ADD (cookie); }

Then there is the Web configuration, which must be matched by a cryptographic algorithm. Our added Cokkiey have to do encryption. Then if you are. NET 4, and 4.5 encryption algorithms are not the same, must be unified, next is the Web. config configuration node <system.web> add

  
<compilation debug= "True" targetframework= "4.0"/>    

  

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.