I have developed ASP.NET MVC application with angular. 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.
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.
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. :
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.
By default ASP.NET uses cookies to identify which requests belong to a particular session. If cookies are not available, a session can be tracked by adding a session identifier to the URL. To disable cookies, set 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?
I added this scenario to automatically call to Logout controller method using aspx page's OnPreRender(EventArgs e) and added below code snippet inside
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)". Rather this yellow error page I want to redirect user to Login controller method.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.