HttpContext.Current.User.Identity.Name使用IIS防爆preSS但不是Visual Studio开发服务器是空的

HttpContext.Current.User.Identity.Name使用IIS防爆preSS但不是Visual Studio开发服务器是空的

问题描述:

HttpContext.Current.User.Identity.Name 时的Visual Studio设置空/空白,以使用本地IIS Web服务器,但是当Visual Studio的设置工作正常为使用Visual Studio开发服务器。

HttpContext.Current.User.Identity.Name is empty/blank when Visual Studio is set to "Use Local IIS Web server" but works correctly when Visual Studio is set to "Use Visual Studio Development Server".

希望你可以复制在Visual Studio 2010或2012(我曾经尝试都)做这个问题,以下内容:

Hopefully you can duplicate this problem in Visual Studio 2010 or 2012 (I have tried both) by doing the following:

创建一个新的ASP.NET空Web应用程序与选定的.NET框架4并将其命名为WindowsAuthTest2。以

Create a new "ASP.NET Empty Web Application" with ".NET Framework 4" selected and name it "WindowsAuthTest2". Replace the contents of Web.config with

<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
    <authentication mode="Windows">
    </authentication>
  </system.web>
</configuration>

接下来,添加一个新的Web窗体名为Default.aspx的项目。以

Next add a new "Web Form" to the project called "Default.aspx". Replace the code in Default.aspx with

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WindowsAuthTest2.Default" %>

<html>
    <head>
        <title></title>
    </head>
    <body>
        <asp:Label ID="Label1" runat="server"></asp:Label>
    </body>
</html>

和以

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WindowsAuthTest2
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Label1.Text = "[" + HttpContext.Current.User.Identity.Name + "]";
        }
    }
}

我没有ReSharper的告诉我这是那些使用语句是不必要的。

I don't have ReSharper to tell me which of those using statements are unnecessary.

然后你可以选择Web服务器Visual Studio将通过右键单击该项目,选择属性(或双击属性,在该项目下),选择网络,并导航到服务器使用部分。

Then you can select which web server Visual Studio will use by right-clicking the project, selecting "Properties" (or by double clicking "Properties" under the project), selecting "Web", and navigating to the "Servers" section.

与使用Visual Studio开发服务器和使用本地IIS Web服务器试试吧。

Try it with "Use Visual Studio Development Server" and "Use Local IIS Web server".

希望你能帮助我弄清楚为什么 HttpContext.Current.User.Identity.Name 当选择使用本地IIS Web服务器是空的。

Hopefully you can help me figure out why HttpContext.Current.User.Identity.Name is empty when "Use Local IIS Web server" is selected.

尼尔·沃森的回答了自己的问题的:

Neil Watson's answer to his own question at:

Authentication在VS2013调试时的问题 - IIS前preSS

解决我的问题。