我们有一个 .net asmx Web 服务,它从 javascript(使用 ASP.Net AJAX)调用,并且需要访问 Session。
[WebMethod(true)]
public string DoSomethingOnTheServer() { }
我们遇到了 session 被读/写请求锁定的问题。有什么方法可以将 Web 服务方法标记为需要对 Session 进行只读访问?
谢谢!
最佳答案
这是一个非常古老的线程,但我在寻找同一问题的答案时偶然发现了它。
我在其他地方找到了答案,并将其留在这里以供其他互联网使用:
在 Global.asax 中,您可以为每个请求指定请求对 session 对象的访问权限,以及是否应该阻止。
private void Application_BeginRequest(object sender, EventArgs e)
{
// This will set the session to read only for asmx services
// This will make the asmx services non blocking for other requests as it doesnt lock the session object
if (Context.Request.Path.Contains(".asmx/"))
{
Context.SetSessionStateBehavior(SessionStateBehavior.ReadOnly);
}
}
这样 asmx 服务始终只有对 session 的只读访问权限,并且不会阻止其他请求
关于asp.net - 对 Web 服务调用中的 session 的只读访问权限?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/935695/