对Web服务调用中的会话的只读访问权限? [英] Readonly access to session in a web service call?

查看:112
本文介绍了对Web服务调用中的会话的只读访问权限?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个.net asmx Web服务,该服务从javascript中调用(使用ASP.Net AJAX),并且需要访问Session.

We have a .net asmx web service that gets called from javascript (using ASP.Net AJAX), and requires access to Session.

[WebMethod(true)]
public string DoSomethingOnTheServer() { }

我们遇到了会话被读写请求锁定的问题.有什么方法可以将Web服务方法标记为需要对Session的只读访问权?

We're running into the problem of session being locked on a read/write request. Is there any way to mark a web service method as requiring read-only access to Session?

谢谢!

推荐答案

这是一个非常老的线程,但是我在寻找相同问题的答案时偶然发现了它.

This is a really old thread, but i stumbled on it in my search for an answer to the same question.

我在其他地方找到了答案,并将其留在这里供我使用其他互联网:

I found the answer else where, and will leave it here for other internets in my place:

在Global.asax中,您可以为每个请求指定请求对会话对象的访问权限,以及是否应阻止该访问对象.

In Global.asax you can specify for each request, what access the request should have to the session object, and thereby if it should block or not.

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服务始终仅对会话具有只读访问权限,而不会阻止其他请求

This way asmx services always only have read only access to the session and will not block other requests

这篇关于对Web服务调用中的会话的只读访问权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆