7

I have a intranet website where I am able to get the user's identity value when run in Local machine.

System.Web.HttpContext.Current.User.Identity.Name.ToString().Substring(3)

But When I deploy the same on IIS 8.5, It finds it blank.

Please help me understand where I am going wrong ?

For impersonation we have to use the specific username and password.

Web.config:

<system.web>
    <authentication mode="Windows" />
        <customErrors mode="RemoteOnly" defaultRedirect="~/Pages/Error/Error.aspx" >
            <error statusCode="404" redirect="~/Pages/Error/404.aspx" />
        </customErrors>
    <identity impersonate="true" userName="user1" password="pass1" />
  </system.web>
<system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <validation validateIntegratedModeConfiguration="false" />
</system.webServer>

IIS settings:

Windows authentication - Enabled
Impersonation  - Enabled
Rest all disabled.

Default app pool - Integrated mode.
Akshay
  • 1,412
  • 2
  • 17
  • 51

3 Answers3

8

IIS settings should be like this:

+------------------------------------+
|           Authentication           |
+------------------------------------+
Name                         Status
------------------------     --------
Anonymous Authentication     Disabled ---+
ASP.NET Impersonation        Enabled     |
Basic Authentication         Enabled     |__ Both are important
Digest Authentication        Disabled    |
Forms Authentication         Disabled    |
Windows Authentication       Enabled  ---+

Use User.Identity.Name to get the logon user and test like this:

protected void Page_Load(object sender, EventArgs e)
{
    if (User.Identity.IsAuthenticated)
    {
        Page.Title = "Home page for " + User.Identity.Name;
    }
    else
    {
        Page.Title = "Home page for guest user.";
    }
}
0

Use HttpContext.Current.User.Identity class to get full information current user.

If HttpContext.Current.User.Identity.IsAuthenticated Then
        currentUserID = UserInfo.UserID
End If
-1

This will display the current users identity.

            int idx;
            String strID;
            strID = WindowsIdentity.GetCurrent().Name;
            strID = strID.Replace('/', '\\');
            idx = strID.IndexOf('\\');
            if (idx != 0)
                strID = strID.Substring(idx + 1).ToLower();
            MessageBox.Show(""+strID);
AkshayV
  • 17
  • 7