0

Good day all I'm completely stumped. I am developing an MVC App using MS VSExpress 2013 for Web, and am at the point where I need to add Windows Authentication. Creating a default MVC App using the Wizard and selecting Windows Authentication, it appears to work fine. Lets call the default App App1, my developed App App2.

Monitoring the Context.User object within Watch for both Apps:

App1 returns:

    User    {System.Security.Principal.WindowsPrincipal}
    System.Security.Principal.WindowsIdentity
    AuthenticationType  "Negotiate" string
    IsAuthenticated         true    bool
    Name          "MyDomain\\Andrew"    string

When using the developed app, the result is as follows: Please note, the returned object is different (App1 = System.Security.Principle.WindowsPrinciple, App2 = System.Web.Security.RolePrinciple.

    User    {System.Web.Security.RolePrincipal} 

    Identity    {System.Security.Principal.GenericIdentity} 
    AuthenticationType    ""    string
    IsAuthenticated    false    bool
    Name                  ""    string

    HttpContext.Current.Request.LogonUserIdentity.Name  "MyDomain\\Andrew"

When switching the developed app Development Server properties to Windows Authentication = Enabled, Anonymous Authentication = Disabled, the result is an immediate:

Server Error in "/" Application. 
Resource cannot be found. 
Http 404... 
Requested URL:/Account/Login

I've checked and compared: Web.config files and IISExpress\config\applicationhost.config settings for both applications.

My limited knowledge (based on reading all the questions on SO I could find), I'm guessing App2 thinks it is using Forms Authentication, not Windows Authentication. App2 is getting the user information through the

HttpContext.Current.Request.LogonUserIdentity.Name object (found this on SO).

I've added:

        <add key="autoFormsAuthentication" value="false" />

to Web.config ... no joy.

Anyone have any idea why the two apps are returning different user objects, and where this can be corrected? Why does App2 not get IsAuthenticated=true from the same IISExpress server as App1?

Thanks

1 Answers1

0

http://www.itorian.com/2013/05/windows-authentication-in-mvc4-with-iis.html

For some strange reason (EDIT Here is the reason-> ASP.NET MVC3 and Windows Auth on IIS keeps redirecting to /Account/Login /EDIT , the wizard generated app1 did not require these two lines within Web.config

<add key="autoFormsAuthentication" value="false" />
<add key="enableSimpleMembership" value="false"/>

After adding the 2nd line, the Context User object returned changed from

System.Security.Principal.GenericIdentity 

to

System.Security.Principal.WindowsPrincipal

and all is well. Also ensure your IISExpress server config file applicationhost.config (within the IISExpress installation folder) contains correct entries as required: Global Entry:

           <windowsAuthentication enabled="true">
                <providers>
                    <add value="Negotiate" />
                    <add value="NTLM" />
                </providers>
            </windowsAuthentication>
Community
  • 1
  • 1