我正在研究MVC 4.0项目。为了在行动方法的授权上做角色,我已经实现了自定义授权属性解决方案的解决方案。但是这个解决方案在审核中不被接受,我被告知要创建一个处理授权和路由的服务。
答案 0 :(得分:0)
On the gloabl.asas.cs file you can add the below event and then do whatever you want to do
protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{
if (Features.UserValidationEnabled)
{
if (!safeExtension && Security.CurrentUser.IsInRole("User"))
{
if (!AccountManager.CheckFlag(Security.CurrentUser, AccountManager.Capabilities.IsValidated))
{
if (!HttpContext.Current.Request.AppRelativeCurrentExecutionFilePath.StartsWith("~/Account", StringComparison.OrdinalIgnoreCase))
{
Response.Redirect("~/Account/Validate");
}
}
}
}}