zoukankan      html  css  js  c++  java
  • ASP.NET MVC 实现登录后返回上一页面操作

      功能描述:当用户请求某页面时,若该页面需要登录后再进行操作,则将用户引导到登录页,登录成功后自动跳转回前一页面

    //登录页视图代码
    public
    ActionResult Login(string repath) { string reUrl=""; if(!String.IsNullOrEmpty(repath)) { reUrl = repath; } else { string hostUrl=""; hostUrl = Request.UrlReferrer == null ? Request.Url.Host : Request.UrlReferrer.Host;
    hostUrl = "http://" + hostUrl;
            pathUrl = Request.UrlReferrer == null ? "/" : Request.UrlReferrer.PathAndQuery;
    reUrl = hostUrl + pathUrl;
    }
         ViewData[ReUrl] = reUrl;
    return View();
    }


    //登录页的post方法
    [post]
    public ActionResult Login(string userName, string pwd, string repath) { ....//该处判断登录是否成功 return Json(code = .., url = repath); }

      思路:转到登录页面时,在controller中记录返回路径ReUrl,然后通过ViewData将ReUrl传到登录页面的隐藏域中,登录请求时又将ReUrl传给post方法的Login,判断完登录是否成功后最后将这个ReUrl又传给前端,前端跳转成功。

      返回路径的传递方向:Login→Login(View)→Login(post)→前端

  • 相关阅读:
    Python-Django学习
    Python+Selenium+Pycharm
    selenium基础实例学习
    Django实例
    Django路由机制
    Selenium爬取电影网页写成csv文件
    Numpy初步
    Python matplotlib图片转化成矢量图并裁剪
    先选先赢问题
    Python退火算法在高次方程的应用
  • 原文地址:https://www.cnblogs.com/flyingpigg/p/7688647.html
Copyright © 2011-2022 走看看