2
votes

I'm implementing a ASP.NET MVC Project with Form authentication. This project is deployment and run OK, but now I need get the current windows user but I don't get it. I try this:

System.Security.Principal.WindowsIdentity.GetCurrent().Name:

but return NT AUTHORITY\NETWORK SERVICE or AUTHORITY\IUSR with this configuration in the IIS.

  • Anonymous Authentication = Enabled.
  • Impersonation = Disabled.
  • Forms Authentication = Enabled.
  • Windows Authentication = Disabled.
  • Basic Authentication = Disabled.

When I Try:

  • Anonymous Authentication = Disabled.

  • Impersonation = Enabled.

  • Forms Authentication = Disabled.

  • Windows Authentication = Enabled.

  • Basic Authentication = Disabled.

    System.Security.Principal.WindowsIdentity.GetCurrent().Name: Domain\User

I get the current user windows correctly but when I go to the web site has not css styles and exist javascript errors.

Javascript Error: Resource interpreted as Stylesheet but transferred with MIME type text/html

I have this web config:

<identity impersonate="true"/>
<authentication mode="Windows">
  <forms loginUrl="~/Account/Login" timeout="2880" />
 </authentication>

I think that error is causing for IIS configuration. *All Folders Permissions : Everyone

1
Don't use impersonation unless you need to access network resources as the given user. Just use Windows Authentication, then reference the User.Identity.Name property of the controller, or HttpContext.Current.User.Identity.Name. Even if you do need to access resources, you should use a WindowsImpersonationContext to do this on the fly.Erik Funkenbusch
Thank por your answer! I will try: Anonymous Authentication = Disabled. Impersonation = Disabled. Forms Authentication = Disabled. Windows Authentication = Enabled. Basic Authentication = Disabled. And I will do User.Identity.Name from the controller baseFranco Morales

1 Answers

0
votes

i had same issue... i tried almost everything but nothing worked. Then i added this line in my webconfig and it worked.
<authorization> <deny users="?" /> </authorization>

also make sure your authentication mode is set to windows. <authentication mode="Windows" />

EG:<system.web> <compilation debug="true" targetFramework="4.6.1" /> <httpRuntime targetFramework="4.6.1" /> <authentication mode="Windows" /> <authorization> <deny users="?" /> </authorization> </system.web>