1
在我的MVC 4網絡應用程序中,當我收到請求時,需要使用自定義綁定器中的模型來執行一些授權邏輯。我的問題是,我不知道如何將我的模型和綁定器連接到filter屬性。可能嗎?將自定義模型綁定器綁定到自定義AuthorizeAttribute
編輯:添加代碼塊
public class FeatureCodeAttribute : AuthorizeAttribute
{
private string featureCode;
private userPermissions;
public FeatureCodeAttribute(string code, UserPermissions permissions)
{
featureCode = code;
userPermissions = permissions;
}
protected override bool AuthorizeCore(HttpContextBase httpContext)
{
if (HasFeature(userPermissions, featureCode))
{
return true;
}
else
{
return false;
}
}
}
我想要做什麼是綁定UserPermissions對象。
謝謝。但我不明白應該放置什麼「任何屬性」?抱歉讓人困惑。請再次檢查我編輯的問題。 –
您想要綁定模型,在模型中您將擁有一些屬性,您可以使用過濾器上下文獲取這些屬性值,並且可以在實際模型綁定之前在此驗證它。 – Mukund