赤瓜礁填海,淘宝货源论坛,广州国大鞋城
用最简单的Session方式记录用户登录状态
public class DefaultController : Controller { protected override void OnActionExecuting(ActionExecutingContext filterContext) { base.OnActionExecuting(filterContext); var controllerName = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName; var userName = Session["UserName"] as String; if (String.IsNullOrEmpty(userName)) { //重定向至登录页面 filterContext.Result = RedirectToAction("Index", "Login", new { url = Request.RawUrl}); return; } } }
public class LoginController : Controller { // GET: Login public ActionResult Index(string ReturnUrl) { if (Session["UserName"] != null) { return RedirectToAction("Index", "Home"); } ViewBag.Url = ReturnUrl; return View(); } [HttpPost] public ActionResult Index(string name, string password, string returnUrl) { /* 添加验证用户名密码代码 */ Session["UserName"] = name; if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\")) { return Redirect(returnUrl); } else { return RedirectToAction("Index", "Home"); } } // POST: /Account/LogOff [HttpPost] public ActionResult LogOff() { Session["UserName"] = null; return RedirectToAction("Index", "Home"); } }
public class HomeController : DefaultController { public ActionResult Index() { return View(); } }
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Blazor server side 自家的一些开源的, 实用型项目的进度之 CEF客户端
.NET IoC模式依赖反转(DIP)、控制反转(Ioc)、依赖注入(DI)
vue+.netcore可支持业务代码扩展的开发框架 VOL.Vue 2.0版本发布
网友评论