MVC Ajax Access Background When session expiration cannot jump to login page problem Resolution

Source: Internet
Author: User

Tag:color   sys    Problem solving    name   nbsp    eva   ase   else   rect   

public class Basecontroller:controller {protected User UserInfo {set {            session["UserInfo"] = value; get {if (session["UserInfo"] = = null) {return                Null                } else {return (User) session["UserInfo"];            }}} protected override void OnActionExecuting (ActionExecutingContext filtercontext) { Verification Code if (FilterContext.ActionDescriptor.ActionName.Equals ("Validatecode", STRINGCOMPARISON.CURRENTCU            Ltureignorecase)) {return; } #region session to determine if (Userinfo==null &&!filtercontext.actiondescriptor.actionname.contain                S ("Login")) {Filtercontext.result =//new redirectresult ("/home/login");//This can also   New Redirecttorouteresult (                     New System.Web.Routing.RouteValueDictionary {"Controller", "Home"}, {"Action", "Login"});            Response.Redirect ("/home/login");//Do not recommend this, it will continue to execute the action return; } #endregion base.        OnActionExecuting (Filtercontext); } }

foreground resolves nested iframe problem (valid for ActionResult return page, invalid with Ajax request)

<script type="text/javascript" >        $ (function () {           //if (window! = top) { Top.location.href = Location.href;}}); </script>       

For AJAX requests, using the above method, the AJAX request is unchanged, the Ajax return status code 302, and login returns the status code 200, the theory is displayed, but

MVC Ajax Access Background When session expiration cannot jump to login page problem Resolution

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.