這是我發起會話ASP.NET + C#HttpContext.Current.Session爲空(裏面的WebService)
protected void Session_Start(object sender, EventArgs e)
{
HttpContext.Current.Session["CustomSessionId"] = Guid.NewGuid();
}
在我的下一個類庫解決方案,我很triyng進行訪問和獲取零例外:
string sess = HttpContext.Current.Session["CustomSessionId"] ;
這是我在web.config中和的app.config配置(在我的庫)
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>
<system.web>
<pages enableSessionState = "true" />
<httpModules>
<add type="System.Web.SessionState.SessionStateModule" name="Session"/>
</httpModules>
<compilation debug="true" targetFramework="4.0" />
</system.web>
(的app.config)
執行HTTP請求的哪個階段是你調用你的類庫中的方法試圖訪問會話? –
很難說,但我認爲這不是你的會議是空的,但HttpContext.Current - 和順便說一句:你知道你試圖將一個Guid轉換爲一個字符串,即使這有效嗎? – Carsten
其實它是在一個web服務,我沒有提到(虐待編輯我的帖子) – SexyMF