HttpContext.Current.User is null even though Windows Authentication is on
HttpContext.Current.User is null even though Windows Authentication is on
The answer to of moving the Application Pool back to classical is just delaying the problem.
Instead leave the application pool alone and move your authenticate check from Application_AuthenticateRequest()
, to the next function in the pipeline:
Application_AuthorizeRequest(object sender, EventArgs e)
By then the integrated Application Pool has completed the windows authentication allow you not to receive null
from HttpContext.Current.User
.
The pipeline can be found here (link provided by CarlosAg).
A visualization of the pipeline can be found on the asp website message lifecycle page. In the controller section checkout the two green boxes "Authentication filters" and "Authorization filters". These are the areas you are messing with.
Runtime Fidelity
In Integrated mode, the ASP.NET request-processing stages that are exposed to modules are directly connected to the corresponding stages of the IIS pipeline. The complete pipeline contains the following stages, which are exposed as HttpApplication events in ASP.NET:
- BeginRequest. The request processing starts.
- AuthenticateRequest. The request is authenticated. IIS and ASP.NET authentication modules subscribe to this stage to perform authentication.
- PostAuthenticateRequest.
- AuthorizeRequest. The request is authorized. IIS and ASP.NET authorization modules check whether the authenticated user has access to the resource requested.
- PostAuthorizeRequest.
- ResolveRequestCache. Cache modules check whether the response to this request exists in the cache, and return it instead of proceeding with the rest of the execution path. Both ASP.NET Output Cache and IIS Output Cache features execute.
- PostResolveRequestCache.
- MapRequestHandler. This stage is internal in ASP.NET and is used to determine the request handler.
- PostMapRequestHandler.
- AcquireRequestState. The state necessary for the request execution is retrieved. ASP.NET Session State and Profile modules obtain their data.
- PostAcquireRequestState.
- PreExecuteRequestHandler. Any tasks before the execution of the handler are performed.
- ExecuteRequestHandler. The request handler executes. ASPX pages, ASP pages, CGI programs, and static files are served.
- PostExecuteRequestHandler
- ReleaseRequestState. The request state changes are saved, and the state is cleaned up here. ASP.NET Session State and Profile modules use this stage for cleanup.
- PostReleaseRequestState.
- UpdateRequestCache. The response is stored in the cache for future use. The ASP.NET Output Cache and IIS Output Cache modules execute to save the response to their caches.
- PostUpdateRequestCache.
- LogRequest. This stage logs the results of the request, and is guaranteed to execute even if errors occur.
- PostLogRequest.
- EndRequest. This stage performs any final request cleanup, and is guaranteed to execute even if errors occur.
By using the familiar ASP.NET APIs, the ability to execute in the same stages as IIS modules makes tasks that were only previously accessible in native ISAPI filters and extensions now possible in managed code.
For example, you can now write modules that do the following:
- Intercept the request before any processing has taken place, for example rewriting URLs or performing security filtering.
- Replace built-in authentication modes.
- Modify the incoming request contents, such as request headers.
- Filter outgoing responses for all content types.
See Developing an IIS 7 and Above Module with .NET for a good example of how to extend IIS with a custom ASP.NET authentication module.
https://www.asp.net/media/4071077/aspnet-web-api-poster.pdf
作者:Chuck Lu GitHub |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
2019-07-22 Walkthrough: My first WPF desktop application
2019-07-22 cropper.js
2019-07-22 ShareX的使用
2016-07-22 Download file using libcurl in C/C++
2016-07-22 EnumWindows function
2015-07-22 修改Hosts