[英]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.