Silverlight,RIA和ASP.Net会话超时 [英] Silverlight, RIA & ASP.Net Session Timeouts

查看:50
本文介绍了Silverlight,RIA和ASP.Net会话超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个要求,当ASP.NET会话过期且用户正在使用Silverlight插件工作时,我们要将用户重定向到登录页面.

We have a requirement where we would like to redirect the user to a login page when ASP.NET Session expires and the user is working in a Silverlight plugin.

因此,情况是,我们有一个运行ASP.Net的旧版应用程序,所有新模块都在Silverlight中,而旧版应用程序加载了Silverlight应用程序.一切正常:-)然后,用户离开办公桌,在ASP.Net会话超时后返回,但随后尝试在使用RIA域服务的Silverlight应用程序中继续进行操作.因为会话超时,所以RIA域服务失败,但是它不会因SessionExpired异常或用户/密码无效而失败,它只会因域异常而失败,该异常类似于在域中引发的真实"异常模型,因此我们无法确定这次是因为会话过期.

So, scenario is, we have a legacy application which runs ASP.Net, all our new modules are in Silverlight, and the legacy app loads the Silverlight application. That all works :-) The user then walks away from their desk and comes back after the ASP.Net Session times out, but then tries to carry on doing something in the Silverlight App, which uses a RIA Domain Service. Because the session has time out, the RIA Domain Service fails, but it does not fail with a SessionExpired exception, nor with a User/Password invalid, it just fails with a Domain Exception which is similar to "real" exceptions thrown in the domain model so we have no way of identifying that this time it was because the session expired.

关于如何使您的ASP.Net会话保持活动状态,有很多答案,我们不想这样做,我们希望该会话过期,但是我们希望能够在Silverlight中优雅地处理它并将用户定向到登录页面.

There are plenty answers for how to keep your ASP.Net session alive, we dont want to do that, we want the session to expire, but we want to be able to handle it gracefully in Silverlight and direct the user to the login page.

我们已经在工作,但是问题是,只要在Silverlight应用程序中引发异常,就会将您重定向到登录页面,这不是预期的行为.我们只想在会话期满时进行重定向.

We have this working, but the problem is whenever an exception is raised in the Silverlight application, this redirects you to the login page, which is not the intended behaviour. We only want to redirect when it is a case of the session expiring.

有什么想法吗?

推荐答案

我只是碰巧遇到了同样的问题.我将以下代码添加到Application_UnhandledException:

I just happened to have the same problem. I added the following code to the Application_UnhandledException:

private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
    // redirect to login on exceptions when user is not logged in
    var domainException = e.ExceptionObject as DomainOperationException;
    if (domainException != null && !WebContext.Current.User.IsAuthenticated) 
    { // probably a server-side timeout has occurred.  
        e.Handled = true;
        HtmlPage.Document.Submit(); // redirect to login page
    }
}

只要有域异常并且用户未登录(我认为必须登录才能看到任何页面),我都会重定向到调用页面,这将导致ASP.NET重定向到登录页面.

Whenever there is a domain exception and the user is not logged in (I assume that the user has to be logged in to see any page), I redirect to the calling page which causes ASP.NET to redirect to the login page.

当您使用.aspx登录表单(我通常使用该表单来防止未经身份验证的用户下载Silverlight代码)时,此解决方案很有用.如果您使用Silverlight注册表格,请在 https://stackoverflow.com/a/8083744/178620 中找到答案>.

This solution is useful when you use an .aspx login form (which I normally use to prevent an unauthenticated user from downloading the Silverlight code). In case you use a Silverlight registration form, you find your answer here https://stackoverflow.com/a/8083744/178620.

这篇关于Silverlight,RIA和ASP.Net会话超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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