Pradeep
Pradeep

Reputation: 5530

Windows authentication issue on local machine

I created an ASP.NET MVC application and then enabled the Windows Authentication. In that, I have used the Entity Framework database first approach model to connect to the SQL database.

After that, I added simple logic to fetch the data from the database and then display it on the UI.

This is the web.config file configuration for database connection string and windows authentication.

 <connectionStrings>
  <add name="DBConnection" connectionString="metadata=res://*/DemoModel.csdl|res://*/DemoModel.ssdl|res://*/DemoModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=xxxx;initial catalog=xxxx;Integrated Security = True;MultipleActiveResultSets=true;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
 </connectionStrings>
  <system.web>
    <authentication mode="Windows">
      <forms defaultUrl="~\demo\Home\Index" timeout="20" slidingExpiration="true" protection="All"/>
    </authentication>
    <customErrors mode="Off">
      <error statusCode="404" redirect="~/Base/PageNotFound"/>
    </customErrors>
    <compilation debug="true" targetFramework="4.6.1">
      <assemblies>
        <add assembly="Microsoft.Build.Framework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxx"/>
      </assemblies>
    </compilation>
    <httpRuntime targetFramework="4.6.1"/>
    <authorization>
      <allow users="*"/>
      <deny users="*"/>
    </authorization>
    <identity impersonate="true" password="" userName=""/>
  </system.web>

When I try to run an application on my local machine, it shows an authentication popup, but even after entering the proper username and password, it keeps on coming.

After I did some research and analysis, I commented the below impersonate attribute of the identity configuration element in the web.config file. Then I tried to run the application on my local machine. It worked as expected.

<!--<identity impersonate="true" password="" userName=""/>-->

Note: The same application I have deployed in IIS with the impersonate attribute is true in the web.config file, there it works as expected.

Can you please tell me the reason why the application is working without impersonate attribute in the web.config file?

Upvotes: 0

Views: 240

Answers (1)

Gabriel Luci
Gabriel Luci

Reputation: 40978

It's possible that the account that you are using to impersonate does not have access to the directory on the file system where your website is located.

Is there a reason you want to use impersonation? It is different and separate from Windows Authentication. You can use Windows Authentication without impersonation, and you can use impersonation without Windows Authentication. Impersonation allows your application to do other things (like access files) using the credentials of the impersonated account.

Without impersonation, your website runs with the default IIS credentials (in IIS) or your own user account (in IIS Express).

Upvotes: 0

Related Questions