Windows身份验证在现有的asp.net网站中不起作用 [英] Windows Authentication not working in existing asp.net site

查看:75
本文介绍了Windows身份验证在现有的asp.net网站中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个现有的asp.net网站,我想对其进行修改以使用Windows身份验证(它在本地Intranet上.)

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

我已经修改了web.config文件以使用Windows身份验证:

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>

我收到的错误消息是:

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

如果我删除:< deny users =?"/> 然后将显示该页面.但是,此代码显示,尽管User不为null,但该用户未登录:

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;
    }

我尝试过的事情:

在Visual Studio中,如果我创建一个新的MVC App,然后选择"Windows身份验证",它将按预期工作,并且用户使用域名登录.

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.

将项目简化为仅web.config和单个aspx页面仍然有效.但是,当我尝试在现有项目(或新的空项目)中使用相同的完全相同的web.config时,会出现相同的错误.

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.

推荐答案

我找到了在Visual Studio中,在解决方案资源管理器中选择项目,然后按 F4 查看项目属性.注意:这些属性位于()窗口中(通常),而不是主(中央)窗口中.

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.

设置:1)Windows身份验证启用和2)禁用匿名身份验证.

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

这篇关于Windows身份验证在现有的asp.net网站中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆