User.Identity.Name sometimes blank with Windows authentication

孤街浪徒 提交于 2019-12-11 05:37:54

问题


My web app uses Windows authentication. All other authentication methods are disabled.

It works at first; User.Identity.Name returns "MYDOMAIN\myuser." However, if I wait 131 seconds (yes, I timed it, though I'm not sure it always takes exactly that long) and reload the page, User.Identity.IsAuthenticated = false and User.Identity.Name = "". At this point I can just reload the page and it works again, for another 131 seconds of inactivity.

Relevant parts of web.config:

<authentication mode="Windows" />
<authorization> 
  <deny users="?" /> 
</authorization>
<identity impersonate="false" />
...
<security>
  <authentication>
    <windowsAuthentication enabled="true" />
    <anonymousAuthentication enabled="false" />
  </authentication>
</security>

More information, possibly relevant:

My solution is deployed to two different IIS applications. The first one is for internal users; it just uses Windows authentication. The second one is for external users; it uses anonymous authentication (in the root folder only) and forms authentication. I'm only having problems with the internal site.


回答1:


The web.config file under the Account folder was allowing anonymous authentication (the one I posted with my question is the main web.config). Not sure how that happened, but removing it fixed the problem.



来源:https://stackoverflow.com/questions/12675593/user-identity-name-sometimes-blank-with-windows-authentication

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