[英]Session is null in asp.net Web Application
我在asp.net應用程序的根目錄上有一個文件夾名稱Controller。 文件夾的類名稱為GraphController.cs
在課堂上,我正在使用以下代碼訪問會話。
HttpContext.Current.Session["name"]
但是Current屬性為null。
另外,我在Web配置中設置會話狀態仍然沒有結果。
WebConfig:
<sessionState mode="InProc" timeout="20"></sessionState>
ASPX:
這是我的代碼在特定間隔后調用該方法
$.ajax({
url: "RestService.svc/GetSGCData", //"Default.aspx/GetSGCData",
type: "POST",
data: "{}",
contentType: "application/json; charset=utf-8", // we are sending in JSON format so we need to specify this
dataType: "json", // the data type we want back.
success: function (value) {
averageWaitTime = parseInt(value);
},
error: function () {
}
});
為了訪問wcf中的會話,請在asp.net中使用REST服務。 您需要以asp.net兼容模式運行服務。
在您的webservice類中添加以下屬性。
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class DashboardGraphService : IDashboardGraphService
{
// class
}
並且還要在WebConfig
文件的<system.serviceModel>
中添加以下標記。
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.