Silverlight, RIA & ASP.Net Session Timeouts

邮差的信 提交于 2019-12-05 09:19:20
slfan

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!