我在我的MVC應用程序中使用基於OWIN的身份驗證。 我所有的控制器和操作方法都使用自定義的AuthorizeAttribute進行保護。ASP.Net MVC 5 - OWIN身份驗證登錄重定向顯示消息
當前,如果用戶請求權限不足的頁面(由於用戶不在可以訪問該功能的組中,用戶無法訪問),他將被重定向到登錄頁面。 此行爲可能會讓用戶感到困惑,因爲他不知道他爲什麼被重定向到登錄頁面。
在這種情況下是否可以顯示消息? ...可以OWIN添加一個參數到登錄頁面請求(類似於ReturnUrl參數)?
感謝您的幫助。
編輯:
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = false)]
public class FunctionAuthorizeAttribute : AuthorizeAttribute
{
public IUserInformationService UserInformationService { get; set; }
public IGenericParameterService GenericParameterService { get; set; }
public String FunctionName { get; set; }
public FunctionAuthorizeAttribute(String functionName)
{
FunctionName = functionName;
}
protected override Boolean AuthorizeCore(HttpContextBase httpContext)
{
var parameter = GenericParameterService.GetCommonParameters();
if (!parameter.CacheSecurityParameter)
parameter = GenericParameterService.GetCommonParameters(false);
return !parameter.EnableAuthentication || UserInformationService.HasAccess(FunctionName)
}
}
你能顯示你的自定義屬性嗎? – Kamo
@Kamo當然,但你不會在那裏發現任何有趣的事情......我想。 我已將代碼添加到問題中。 – musium