LogonUserIdentity.Name与User.Identity.NameName、LogonUserIdentity、Identity、User

2023-09-07 16:08:25 作者:老爷子@

我有一个是在4.0框架运行的ASP.NET Web窗体应用程序项目。我很熟悉的Web应用程序,但没有这么多的Web窗体应用程序。我跑进今天他们两个人之间的显着差异,我很困惑,为什么这种差异的存在。

I have an ASP.NET Web Forms Application project that is running upon the 4.0 framework. I'm very familiar with Web Applications, but not so much with Web Forms Applications. I ran into a notable difference between the two of them today, and I'm confused at why this difference even exists.

通常情况下,在一个Web应用程序,如果我要确定谁是页面的当前用户的话,我只是找回自己的域日志,从 User.Identity.Name 。所以,我很困惑,当我按F5在我的调试环境中运行我的解决方案(我网页的表格应用程序!),发现User.Identity.Name是空的。所以,我再一派User.Identity.Name是空的,并撞上了墙的链接,大多都涉及有这个问题的人,当他们没有禁用匿名身份验证在IIS中。当然,这不是我的问题(我认为),因为我刚刚从Visual Studio 2012在这里调试。

Typically, in a Web Application, if I want to determine who the current user of the page is then I just retrieve their domain log-in from User.Identity.Name. So, I was quite perplexed when I hit F5 to run my solution (my Web Forms Application!) in my debug environment and found that the User.Identity.Name was empty. So I then googled "User.Identity.Name is empty" and ran into a wall of links that mostly all dealt with people having this problem when they hadn't disabled Anonymous Authentication in IIS. Of course, that's not my problem (I think) as I'm just debugging from Visual Studio 2012 here.

不过,我继续挖掘,最终发现在HttpContext的,是不是空的,返回用户的域日志,在一些不起眼的财产。该物业是 HttpContext.Current.Request.LogonUserIdentity.Name 。这使我对我的问题...

However, I continued to dig and eventually found some obscure property on the HttpContext that is not empty and returns the user's domain log-in. The property is HttpContext.Current.Request.LogonUserIdentity.Name. Which leads me to my question...

问题:在我的Web窗体应用程序,这是为什么User.Identity.Name空,但HttpContext.Current.Request.LogonUserIdentity.Name不是

Question: In my Web Forms Application, why is User.Identity.Name empty but HttpContext.Current.Request.LogonUserIdentity.Name is not?

在此先感谢您的帮助!

编辑:忘了说明我有我的web.config

Forgot to state what I have in my web.config (because I'm sure it'll be asked for if I don't!).

<system.web>
  <customErrors mode="Off" />
  <compilation debug="true" targetFramework="4.0" />
  <authentication mode="Windows"/>
</system.web>
<system.webServer>
    <httpProtocol>
      <customHeaders>
        <clear />
        <add name="X-UA-Compatible" value="IE=10,chrome=1; IE=9,chrome=1; IE=8,chrome=1; IE=edge,chrome=1" />
      </customHeaders>
    </httpProtocol>
    <modules runAllManagedModulesForAllRequests="true" />
    <defaultDocument>
      <files>
        <add value="Home.aspx" />
      </files>
    </defaultDocument>
  </system.webServer>

这是pretty的很多都是我在我的web.config除了标签的的EntityFramework。

That's pretty much all I have in my web.config besides tags for the EntityFramework.

推荐答案

我发现我自己的答案。在对ApplicationHost.config的IIS防爆preSS被设置为不允许Windows身份验证。我只需设置启用=真,然后User.Identity不再是空的。

I found the answer on my own. The applicationhost.config for IIS Express was set to not allow windows authentication. I simply set enabled="true" and then User.Identity was no longer empty.

<windowsAuthentication enabled="true">
  <providers>
    <add value="Negotiate" />
    <add value="NTLM" />
  </providers>
</windowsAuthentication>

编辑: 1)我的道歉缺乏信息。其实我有我修改我原来的答复的XML标记,但我似乎忘记了它们标记为是code。通过单击code示例按钮等XML标签从来没有显示出来!他们现在应该是可见的。

1) My apologies for the lack of information. I actually had the XML tags that I modified in my original answer, but I apparently forgot to mark them as being code by clicking on the Code Sample button, and so the XML tags were never displayed! They should be visible now.

2)对ApplicationHost.config的,我修改的位置倒在我的文档几个文件夹。确切位置为:C:\用户[用户] \我的文档\ IISEx preSS \ CONFIG

2) The location of the applicationhost.config that I modified is down a few folders under My Documents. The exact location is: C:\Users[your user]\My Documents\IISExpress\config

 
精彩推荐
图片推荐