3
に基づいて、フィルタの実行をスキップ真のauthorize属性を実行しないで、自分の行動を実行に移行する直接(LocationProfile())
は、私は次のように認定されているアクションが持っている他のフィルタのASP .NET
は、このタスク
に基づいて、フィルタの実行をスキップ真のauthorize属性を実行しないで、自分の行動を実行に移行する直接(LocationProfile())
は、私は次のように認定されているアクションが持っている他のフィルタのASP .NET
は、このタスク
あなたは内蔵のその機能を持っているあなたのown version of the Authorize attributeをロールバックする必要がありますを達成するためにどのような方法があります。上記のリンクC#のコーナーポストから付属:AuthorizeCore方法で
public class CustomAuthorizeAttribute : AuthorizeAttribute
{
Entities context = new Entities(); // my entity
private readonly string[] allowedroles;
public CustomAuthorizeAttribute(params string[] roles)
{
this.allowedroles = roles;
}
protected override bool AuthorizeCore(HttpContextBase httpContext)
{
bool authorize = false;
foreach (var role in allowedroles)
{
var user = context.AppUser.Where(m => m.UserID == GetUser.CurrentUser/* getting user form current context */ && m.Role == role &&
m.IsActive == true); // checking active users with allowed roles.
if (user.Count() > 0)
{
authorize = true; /* return true if Entity has current user(active) with specific role */
}
}
return authorize;
}
protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
{
filterContext.Result = new HttpUnauthorizedResult();
}
}
、あなたは説明の状況を考慮して、あなたのチェックを追加する必要があります。
私はそれを試して、それは魅力のように動作します。 – Abdallah