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