zoukankan      html  css  js  c++  java
  • 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:

    1. BeginRequest. The request processing starts.
    2. AuthenticateRequest. The request is authenticated. IIS and ASP.NET authentication modules subscribe to this stage to perform authentication.
    3. PostAuthenticateRequest.
    4. AuthorizeRequest. The request is authorized. IIS and ASP.NET authorization modules check whether the authenticated user has access to the resource requested.
    5. PostAuthorizeRequest.
    6. 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.
    7. PostResolveRequestCache.
    8. MapRequestHandler. This stage is internal in ASP.NET and is used to determine the request handler.
    9. PostMapRequestHandler.
    10. AcquireRequestState. The state necessary for the request execution is retrieved. ASP.NET Session State and Profile modules obtain their data.
    11. PostAcquireRequestState.
    12. PreExecuteRequestHandler. Any tasks before the execution of the handler are performed.
    13. ExecuteRequestHandler. The request handler executes. ASPX pages, ASP pages, CGI programs, and static files are served.
    14. PostExecuteRequestHandler
    15. 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.
    16. PostReleaseRequestState.
    17. 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.
    18. PostUpdateRequestCache.
    19. LogRequest. This stage logs the results of the request, and is guaranteed to execute even if errors occur.
    20. PostLogRequest.
    21. 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:

    1. Intercept the request before any processing has taken place, for example rewriting URLs or performing security filtering.
    2. Replace built-in authentication modes.
    3. Modify the incoming request contents, such as request headers.
    4. 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

  • 相关阅读:
    藏!Java编程技巧之单元测试用例编写流程 原创 常意 阿里技术 2021-05-12
    时间,遵循rfc3339标准格式 unix时间戳
    微软面试题: LeetCode 240. 搜索二维矩阵 II 出现次数:3
    微软面试题: LeetCode 69. x 的平方根 出现次数:3
    微软面试题: LeetCode 138. 复制带随机指针的链表 出现次数:3
    微软面试题: LeetCode 384. 打乱数组 出现次数:3
    微软面试题: LeetCode 207. 课程表 出现次数:3
    微软面试题: LeetCode 98. 验证二叉搜索树 出现次数:3
    CF1537E2 Erase and Extend (Hard Version) 题解
    洛谷 P4332 [SHOI2014]三叉神经树 题解
  • 原文地址:https://www.cnblogs.com/chucklu/p/13362831.html
Copyright © 2011-2022 走看看