Wednesday, 23 May 2012

windows authentication in iis 7 ASP.NET 4

Step 1)  Create new Website choose .NET 4.0  and empty website. It must be created in IIS 7/7.5
Step 2) Create another (virtual) directory  called UPLOADS and add aspx file + web.config as shown in the picture.

Step 3)  Edit Web.config file

      <authentication mode="
      <identity impersonate="
true" />

Step 4) User should disable Anonymous Authentication (User can change using inetmgr.exe)
          or add configuration entries in web.config file as shown below.

        <anonymousAuthentication enabled="false" />
        <windowsAuthentication enabled="true" />

<validation validateIntegratedModeConfiguration="false" />

Step 5)  Add   default.aspx in uploads directory
//change Page_load event ...

    protected void Page_Load(object sender, EventArgs e)
Response.Write("Authentication Type="+HttpContext.Current.User.Identity.AuthenticationType+"<br/>");
Response.Write("Logged in username="+HttpContext.Current.User.Identity.Name + "<br/>");