使用SignalR和传输模式长轮询时Asp.net不超时 [英] Asp.net session never expires when using SignalR and transport mode long polling

查看:756
本文介绍了使用SignalR和传输模式长轮询时Asp.net不超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个使用SignalR其通知机制等问题是,当我们在浏览使用IE我们的web应用程序,SignalR使用长轮询作为其传输类型从而发回请求到我们的Web服务器的Web应用程序,因此不超时无不管多久浏览器处于闲置状态。

We have a web application that uses SignalR for its notification mechanism.The problem is when we are browsing our web application using IE ,SignalR uses Long Polling as its transport type thus sends back requests to our web server therefore Session never expires no matter how long the browser is idle.

我们在想,也许我们可以赶上在Global.asax中的要求,看看他们是来自SingalR和会话超时设置为剩余时间(我不认为这是一个简单的解决方案)。

We were thinking that maybe we could catch the requests in Global.asax and see if they were from SingalR and set the session timeout to the remaining time (Which I don't think it's a straightforward solution).

有我们缺少任何其他解决方案?

Is there any other solution the we are missing ?

推荐答案

我目前使用的解决方法是一个IHttpModule的检查,如果请求是Signalr要求,如果是删除身份验证cookie,这将prevent的被重置,所以如果你的会话超时为20min,唯一的要求是Signalr用户会话仍然超时,用户必须重新登录ASP.net会话超时。

The workaround I am currently using is an IHttpModule to check if the request is a Signalr request, if so remove the authentication cookie, this will prevent the ASP.net session timeout from being reset, so if your Session Timeout is 20min and the only requests are Signalr the users session will still timeout and the user will have to login again.

    public class SignalRCookieBypassModule : IHttpModule
    {
        public void Init(HttpApplication application)
        {
            application.PreSendRequestHeaders += OnPreSendRequestHeaders;
        }

        private bool IsSignalrRequest(string path)
        {
            return path.IndexOf("/signalr/", StringComparison.OrdinalIgnoreCase) > -1;
        }

        protected void OnPreSendRequestHeaders(object sender, EventArgs e)
        {
            var httpContext = ((HttpApplication)sender).Context;
            if (IsSignalrRequest(httpContext.Request.Path))
            {
                // Remove auth cooke to avoid sliding expiration renew
                httpContext.Response.Cookies.Remove(DefaultAuthenticationTypes.ApplicationCookie);
            }
        }

        public void Dispose()
        {
        }
    }

我觉得这是一个真正的黑客解决方案,因此很想让其他的想法,以prevent会话超时当数据从服务器推送到客户端更新,或当JavaScript客户端轮询数据的端点。

I feel this is a real hack solution so would love so other ideas to prevent session timeout renew when data is pushed to the client from the server, or a when javascript client polls an endpoint for data.

这篇关于使用SignalR和传输模式长轮询时Asp.net不超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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