HttpContext.Current.User not populated with Windows Authentication enabled

假装没事ソ 提交于 2019-11-29 08:14:41

I believe you need to make sure that anonymous access is turned off in IIS for the site/virtual.

Make sure your <httpModules> section hasn't been cleared. Your machine's web.config file should include a snippet like this:

    <httpModules>
        <!-- ... -->
        <add name="WindowsAuthentication" type="System.Web.Security.WindowsAuthenticationModule" />
        <!-- ... -->
        <add name="AnonymousIdentification" type="System.Web.Security.AnonymousIdentificationModule" />
        <!-- ... -->
    </httpModules>

The important element here is WindowsAuthentication. Make sure that it's in your %SystemRoot%\Microsoft.NET\Framework\v2.0.50727\CONFIG\Web.config file. Also, make certain that both your own web site and any web.config file that appears in a "parent" site site or folder does not have a <clear/> tag in its <httpModules> section. Without the WindowsAuthentication module, it doesn't matter if the browser forces you to log in or not... ASP.NET will never actually set the User property without this module included.

Ordering of httpModules is also significant, and in particular I believe the WindowsAuthentication module needs to appear before the AnonymousIdentification one.

Try adding to get the behavior you want? When impersonation isn't turned on, a lot still happens under the name of NETWORK SERVICES or the ASPNET user

And here is Hanselman blog post that has the other crazy idea that came to mind:

Some ideas:

On the site configuration, pull up the 'ASP.NET Configuration Settings' dialog. On the 'Authentication' tab, is the 'Authentication mode' set to 'Windows' ()? On the 'Application' tab, did 'Local impersonation' get set (I think it should be unchecked).

Did your server get dropped off the domain? Did the user running the app pool change? Did domain policies change, preventing the server from impersonating the user for purposes of auth checks (not delegation)?

Have you tried re-installing the asp.net extensions for your site? (This is a big topic in itself.)

You could check the HttpContext.SkipAuthorization flag programmatically.

Where do you check for this user? In the request cycle there are some events fired before the authorization takes place.

If you are testing on Vista, Windows 7 or Windows Server 2008 there can be other differences, because the ASP.Net and IIS pipeline are integrated on IIS 7's default configuration.

Have you tried adding identity impersonation:

<identity impersonate="true" />

to the web.config?

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