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.
Web namespace (which contains the HttpContext class), you can reference the members of HttpContext on an . aspx page without using the fully qualified class reference to HttpContext. For example, you can use User.Identity.Name to get the name of the user on whose behalf the current process is running.
AddTransient<IPrincipal>(provider => provider. GetService<IHttpContextAccessor>(). HttpContext. User);
identity. isauthenticated is False when a user is already logged in.
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.";
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With