Windows Authentication not working in existing asp.net site

扶醉桌前 提交于 2021-02-11 18:06:28

问题


I have an existing asp.net site that I want to modify to use Windows authentication (It is on a local intranet.)

I have modified the web.config file to use Windows Auth:

<configuration>
 <system.web>
  <authentication mode="Windows"/>
  <authorization>
  <deny users="?"/>
 </authorization>
 <compilation debug="true"/>
</system.web>

The error message that I get is:

401.2.: Unauthorized: Logon failed due to server configuration.

If I remove: <deny users="?"/> Then the page is shown. However this code shows that although the User is not null, the user is not logged in:

    protected void Page_Load(object sender, EventArgs e)
    {
        var userName = HttpContext.Current.User.Identity.Name;
    }

What I have tried:

In Visual Studio, if I create a new MVC App, and select "Windows Authentication" it works as expected, and the user is logged in with the domain name.

Reducing the project to just the web.config and a single aspx page still works. But when I try to use the same exact web.config in an existing project (Or a new empty project) I get the same error.

So there must be some other setting somewhere that needs to be set, but I cannot determine what it is.


回答1:


I found the answer to this here

In Visual Studio, select the Project in the Solution Explorer, then press F4 to view the project properties. Note: These properties are on a side window (typically) not the main (center) window.

Set: 1) Windows Authentication to Enabled and 2) Anonymous Authentication to Disabled.



来源:https://stackoverflow.com/questions/24186050/windows-authentication-not-working-in-existing-asp-net-site

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!