Silverlight、RIA 和ASP.Net 会话超时

发布于 2024-12-01 13:11:12 字数 548 浏览 1 评论 0原文

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

因此,场景是,我们有一个运行 ASP.Net 的旧应用程序,所有新模块都位于 Silverlight 中,并且旧应用程序加载 Silverlight 应用程序。这一切都有效:-) 然后,用户离开办公桌并在 ASP.Net 会话超时后返回,但随后尝试在使用 RIA 域服务的 Silverlight 应用程序中继续执行某些操作。由于会话超时,RIA 域服务失败,但它不会因 SessionExpired 异常而失败,也不会因用户/密码无效而失败,它只是因域异常而失败,这与域中抛出的“真实”异常类似模型,因此我们无法确定这次是因为会话过期。

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

我们已经做到了这一点,但问题是每当 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.

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.

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.

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.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

作业与我同在 2024-12-08 13:11:12

我只是碰巧遇到了同样的问题。我将以下代码添加到 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 的调用页面重定向到登录页面。

编辑:当您使用 .aspx 登录表单(我通常使用它来防止未经身份验证的用户下载 Silverlight 代码)时,此解决方案非常有用。如果您使用 Silverlight 注册表单,您可以在此处找到答案 https://stackoverflow.com/a/8083744/178620

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
    }
}

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.

EDIT: 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文