我在我的HomeController
中進行了自定義授權。 我有這樣的:重定向到Login.cshtml MVC 5剃鬚刀
[CustomAuthorize]
ActionResult Planning()
當用戶連接時,他能達到一個特定的頁面。我爲此做了網址。但是,如果用戶沒有連接,我想重定向他到登錄頁面,但我有一個URL錯誤"~/Views/Account/Login.cshtml"
。
在此先感謝!
編輯我的代碼:
public class CustomAuthorizeAttribute : AuthorizeAttribute
{
public override void OnAuthorization(AuthorizationContext filterContext)
{
if (System.Web.HttpContext.Current.User.Identity != null
&& System.Web.HttpContext.Current.User.Identity.IsAuthenticated)
{
if (System.Web.HttpContext.Current.User.IsInRole("student"))
{
var result = new ViewResult();
result.ViewData.Model = "Home";
result.ViewName = "~/Views/Roles/Student.cshtml";
result.MasterName = "~/Views/Shared/_Layout.cshtml";
filterContext.Result = result;
}
}
else
{
here the redirection to the Account/Login page
}
}
}
顯示您的'CustomAuthorize'屬性的代碼... – HTX9
我的代碼現在存在 – Memo