asp: Integrated domain account Login

Source: Internet
Author: User
Tags ticket

Before we have already talked about the asp: Windows Authentication , now let's talk about domain account login,

That's not the same thing. Oh, Windows authentication is more of a permission to access resources, and domain account login is more authentication for user login, he is generally used in conjunction with Forms authentication

Demo uses the previous asp: Forms authentication

1, change the Logincontroller, as follows

1      Public classLogincontroller:controller2     {3          Publicactionresult Index ()4         {5             varRETURNURL = request["RETURNURL"];6 7             if(Request.httpmethod = ="POST")8             {9                 TryTen                 { One                     //format: domain \ Logon name A                     varDomainUser = request["userid"]; -                     varPassword = request["Password"]; -                     varUserarr = Domainuser.split ('\\'); the  -                     varEntry =NewDirectoryEntry (string. Concat ("ldap://", userarr[0]), userarr[1], password); -                     varSearch =NewDirectorySearcher (entry); -                     varresult =Search. FindOne (); +                     if(Result! =NULL) -                     { +                         varTicket =NewFormsAuthenticationTicket ( A                             1, atuserarr[1], - DateTime.Now, -DateTime.Now.AddMinutes ( -), -                             true, -                             "role1,role2,role3,role4", -                             "/" in                         ); -  to                         varCookie =NewHttpCookie (Formsauthentication.formscookiename, Formsauthentication.encrypt (ticket)); +Cookies. HttpOnly =true; - HttpContext.Response.Cookies.Add (cookie); the  *                         returnRedirect (RETURNURL); $                     }Panax Notoginseng                 } -                 Catch(Exception ex) the                 { +                     //throws an exception.  A                 } the             } +  -Viewbag.returnurl =ReturnUrl; $  $             returnView (); -         } -}

2, the operation of the project, the login page appears, normal, because our default home page added permission limit, enter the domain account password

3. Login

No problem at all, isn't it simple?

asp: Integrated domain account Login

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.