MVC Access IFRAME page skip to login page after session expires

Source: Internet
Author: User

Web-side development, users often log in after the session to save user information, session stored in the server, when the user is not operating for a long time, we would like the server to save the session expires, this time, because the session of the user information can not be taken, Requires the user to log back in and save the session again.

ASP. NET MVC provides a filter that allows us to easily control what to do when the action is accessed, and to jump to the page after the session expires. We can encapsulate the controller's OnActionExecuting method as the base controller, as follows:

public class Basecontroller:controller {protected User UserInfo            {set {session["UserInfo"] = value; get {if (session["UserInfo"] = = null) {return n                Ull                } else {return (User) session["UserInfo"];            }}} protected override void OnActionExecuting (ActionExecutingContext filtercontext) { #region session to determine if (Userinfo==null &&!filtercontext.actiondescriptor.actionname.contains ("L                Ogin ")) {Filtercontext.result = new Redirectresult ("/home/login ");            Return } #endregion base.        OnActionExecuting (Filtercontext); } }

But here's the new Redirectresult ("/home/login"); just the return of the action to/home/login, if the user operation of the page is nested in the IFRAME, this time, just the point of the IFRAME changed, Ask the Address bar is not the point of change, for this situation, the front page/home/login can be limited, as follows:

@{    Layout = "~/views/shared/_layout.cshtml";} <! DOCTYPE html>

Refer to the following: http://blog.csdn.net/u012251421/article/details/50332513

MVC Access IFRAME page skip to login page after session expires

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.