简体   繁体   English

在MVC项目中添加了ASP.NET页面中的会话超时以呈现SSRS报告

[英]Session timeout in ASP.NET page added in MVC project for rendering SSRS report

I have developed ASP.NET MVC application with angular. 我已经开发了带角度的ASP.NET MVC应用程序。 Later stage I found that my company is using SSRS based reporting solution for all the report requirement, hence I have added one .aspx page to show these reports using report viewer control. 稍后阶段,我发现我的公司正在使用基于SSRS的报告解决方案来满足所有报告要求,因此我添加了一个.aspx页面以使用报告查看器控件显示这些报告。

The problem here is that, I want to check if Session has expired in .aspx page and call MVC's logout action method and redirect users to MVC's login action method. 这里的问题是,我想检查Session是否在.aspx页中过期,并调用MVC的注销操作方法,并将用户重定向到MVC的登录操作方法。

Please help on how I can achieve this? 请帮助我如何实现这一目标?

Thanks, Vijay 谢谢,维杰

Check whether the Session object exists in your page, if you're setting username in your session, it will be null, when session has expired. 检查会话对象是否存在于您的页面中,如果您在会话中设置用户名,则当会话过期时该用户名将为null。 :

if (Session["UserName"] != null)
{
   // Session has not expired
}
else
{
    // Redirect To login since session expired
}

You can increase the time out value in minutes using the timeout attribute of sessionState element in web.config. 您可以使用web.config中的sessionState元素的超时属性以分钟为单位增加超时值。

By default ASP.NET uses cookies to identify which requests belong to a particular session. 默认情况下,ASP.NET使用cookie来识别哪些请求属于特定会话。 If cookies are not available, a session can be tracked by adding a session identifier to the URL. 如果cookie不可用,可以通过将会话标识符添加到URL来跟踪会话。 To disable cookies, set sessionState cookieless="true". 要禁用cookie,请设置sessionState cookieless =“ true”。

<sessionState mode="StateServer" cookieless="false" timeout="120"/>

thanks for this suggestion, I tried by adding this code snippet, but the issue is when session got timeout I want my aspx page automatically call Logout method from controller and later I want same aspx page should redirect to login page? 感谢您的建议,我尝试添加此代码段,但是问题是会话超时时,我希望我的aspx页面自动从控制器调用Logout方法,以后我希望同一个aspx页面应重定向到登录页面吗?

I added this scenario to automatically call to Logout controller method using aspx page's OnPreRender(EventArgs e) and added below code snippet inside 我添加了此方案以使用aspx页面的OnPreRender(EventArgs e)自动调用注销控制器方法,并在内部添加了以下代码片段

protected void base.OnPreRender(e){
    Controls.Add(new LiteralControl(
    String.Format("<meta http-equiv='refresh' content='{0};url={1}'>",
    Session.Timeout * 60, "/main.mvc/logout?random=report")));
}

It is calling Logout method like in above code, but the later on I am getting error page with status something like "The report execution mt1vqsixnjiff145dvbe1o55 has expired or cannot be found. (rsExecutionNotFound)". 它正在像上面的代码中那样调用Lo​​gout方法,但是稍后我会收到错误页面,其状态类似“报告执行mt1vqsixnjiff145dvbe1o55已过期或找不到。(rsExecutionNotFound)”。 Rather this yellow error page I want to redirect user to Login controller method. 而是这个黄色的错误页面,我想将用户重定向到登录控制器方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM