我有一個複雜的應用程序,其中包含許多Web Api調用,它們需要數據庫中的權限檢查。一個例子簡單的API調用我可能是:ASP.Net MVC Web API的自定義授權
[HttpGet]
public IEnumerable<StudentContact> GetStudentContacts(int id)
{
return db.StudentContacts.AsNoTracking().Where(n => n.StudentId == id && n.Current_Record == true).OrderBy(n => n.RankOrder);
}
而要做到權限檢查我必須做到以下幾點:
int staffID = (User as CustomPrincipal).UserId;
int siteId = Functions.GetSiteIdFromCookie();
if (Functions.UserHasAccess(staffID, AccessLevels.access_StudentDetailsUpdate,siteId) == true) return true;
else return false;
我想達成什麼是創建一個自定義授權註解所以我可以有:
[HttpGet]
[PermissionAuth(AccessLevels.access_StudentDetailsUpdate,AccessLevels.access_StudentDetailsReadOnly)]
public IEnumerable......
而我可能需要有一個選項和/或即兩者都是真實的或一個是真實的。誰能幫忙?
你看着使用過濾器? – Liath
不容易設置自定義過濾器嗎?它會拒絕訪問該功能嗎? – user1166905