Sunday, 1 May 2016

How to windows authentication in mvc?

Firstly, in web.config to configure-:

<system.web>  
    <authentication mode="Windows"></authentication>
    <authorization>
      <deny users="?" />
    </authorization>
 </system.web>

After that Project property (F4 Click)
Windows Authentication Diable and Autonymous Authentication Enabled.

After that it works.
  string domainUser = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
            string IsAuthentication = System.Web.HttpContext.Current.Request.IsAuthenticated.ToString();
            string[] paramsLogin = domainUser.Split('\\');
            string UserName = paramsLogin[1].ToString();

No comments:

Post a Comment