Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

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

share|improve this question
    
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 Apr 13 at 14:03
    
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 base – Franco Morales Apr 14 at 13:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.