問題描述
我在 global.asax 中為當前線程設置了一個自定義安全主體對象,一切正常,通常沒有問題.
I have a custom security principal object which I set in the global.asax for the current thread and all is well, no problems normally.
但是,我只是通過讓頁面提供圖像來添加動態圖像功能,每當加載該動態圖像頁面時,System.Web.HttpContext.Current.Session 在 global.asax 中為 null,這會阻止我從那時起,將安全主體設置為正常和級聯問題.
However, I'm just adding a dynamic image feature by having a page serve up the image and whenever that dynamic image page is loaded the System.Web.HttpContext.Current.Session is null in global.asax which prevents me from setting the security principal as normal and cascading problems from that point onwards.
通常情況下,global.asax 中的 Session 僅在用戶登錄開始時的會話期間為空一次,之后它始終可用,但有這個例外.
Normally the Session is null in global.asax only once during a session at the start when the user logs in, afterwards it's always available with this single exception.
當瀏覽器遇到原始頁面中的圖像標簽時加載動態圖像頁面,即
The dynamic image page is loaded when the browser comes across an image tage in the original page i.e.
我猜這是瀏覽器請求該頁面而不發送一些憑據這一事實的某些方面?
I'm guessing that this is some aspect of the fact that the browser is requesting that page without sending some credentials with it?
任何幫助將不勝感激.
推薦答案
John,
我假設您正在為處理程序使用 ashx 處理程序.如果是這樣,請確保從 IRequiresSessionState 派生,例如:
I'm assuming you're using an ashx handler for the handler. If so, be sure to derive from IRequiresSessionState for example:
public class Images : IHttpHandler, System.Web.SessionState.IRequiresSessionState
{ }
如果您不使用 ashx,您能描述一下動態圖像頁面的含義嗎?
If you're not using an ashx can you describe what you mean by dynamic image page?
喬希
這篇關于Asp.net System.Web.HttpContext.Current.Session 在 global.asax 中為 null的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!