【问题标题】:HttpContext.Current.User.Identity.Name empty when debugging in visual studio在 Visual Studio 中调试时 HttpContext.Current.User.Identity.Name 为空
【发布时间】:2014-01-24 01:46:15
【问题描述】:

下面是 web.config

<authentication mode="Windows" />
    <authorization>
            <allow users="*"/>
            <deny users="?" />
    </authorization>

但是当我在 Visual Studio 中调试时,HttpContext.Current.User.IsAuthenticated 为 false,而 HttpContext.Current.User.Identity.Name 保持为空

为什么会这样?


当我将 web.config 更改为此时,显示 401 错误...

 <authorization>

      <deny users="?" />
    </authorization>

【问题讨论】:

  • 答案可能会有所不同,但请查看this post。它有一些很棒的资源。
  • @NicholasV。请看一下我的编辑,刚刚在 web.config 中禁用了匿名访问,但显示未经授权的访问错误..

标签: asp.net visual-studio authentication visual-studio-2012


【解决方案1】:

刚才通过在“属性”页面中将“使用本地IIS Web服务器”更改为“使用Visual Studio开发服务器”解决了这个问题

【讨论】:

    【解决方案2】:

    您的配置允许匿名用户。您只会获得经过身份验证的用户的用户名。

    <authorization>
        <!-- Deny anonymous users -->
        <deny users="?" />
    
        <!-- Allow everyone else (authenticated users) -->
        <allow users="*" />
    </authorization>
    

    确保您已在 IIS 中安装并激活了 Windows 身份验证组件。

    【讨论】:

    • 刚刚试了下你的解决方法,结果还是一样,请看我的编辑..
    【解决方案3】:

    自 Visual Studio 2013 起“Visual Studio Development Server”不再可用,我们需要选择 IIS Express 并确保我们已在 applicationhost.config 文件中启用 Windows 身份验证

    <windowsAuthentication enabled="true">
    

    除了按照@sisve 的回答所述配置我们的 IIS Express。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-11
      • 1970-01-01
      • 1970-01-01
      • 2011-01-22
      • 2019-10-30
      相关资源
      最近更新 更多