Asp.Net中判断是否登录,及是否有权限?
生活随笔
收集整理的這篇文章主要介紹了
Asp.Net中判断是否登录,及是否有权限?
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
不需要在每個頁面都做判段,
方法一:只需要做以下處理即可
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc;namespace HeathRoom.Controllers {public class BaseController : Controller{//// GET: /Base/protected override void OnActionExecuting(ActionExecutingContext filterContext){if (Request.Cookies["homeid"] == null){//filterContext.Result = RedirectToRoute("Login");filterContext.Result = RedirectToRoute(new { Controller = "Login", Action = "Login" }); base.OnActionExecuting(filterContext); }}} }然后,讓所有的Controller繼承自BaseController。
?方法二: 使用自定義AuthorizeAttribute屬性
customAuthorizedAttribute:authorizeAttribute
{
override public void OnAuthorization (AuthorizationContext filterContext)
{
??? // 進行邏輯判斷
}
}
給需要進行驗證的controller 或者action添加屬性標簽[customAuthorized]
轉載于:https://www.cnblogs.com/tianboblog/p/3255666.html
總結
以上是生活随笔為你收集整理的Asp.Net中判断是否登录,及是否有权限?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 转:Java异常分类以及相应处理机制
- 下一篇: 一 ASP.NET Html 表单