अपनी एक्शन विधि पर प्राधिकरण एट्रिब्यूट न जोड़ें जहां कभी भी आपको उदाहरण के लिए जरूरी नहीं है।
मेरे कस्टम विशेषता
public class AuthorizationFilterAttribute : AuthorizeAttribute
{
Some code...
}
मेरे नियंत्रक
public class UserController : BaseController, IDisposable
{
[AuthorizationFilterAttribute]
public ActionResult UserList()
{
//Authorize attribute will call when this action is executed
}
public ActionResult AddUser()
{
//Authorize attribute will not call when this action is executed
}
}
मुझे आशा है कि आप मेरी बात है कि मैं क्या आप कहने की कोशिश कर रहा हूँ मिल गया।
================= अपडेट किया गया उत्तर ========================== ===================== नीचे एक और विशेषता बनाएं।
public sealed class AnonymousAttribute : Attribute { }
कृपया अपने ऑन-प्राधिकरण विधि पर कोड नीचे डालें।
public override void OnAuthorization(AuthorizationContext filterContext) {
bool checkForAuthorization = filterContext.ActionDescriptor.IsDefined(typeof(AnonymousAttribute), true)
|| filterContext.ActionDescriptor.ControllerDescriptor.IsDefined(typeof(AnonymousAttribute), true);
if (!skipAuthorization) {
base.OnAuthorization(filterContext);
}
}
स्रोत
2012-03-06 10:02:46
'(1): 'मुझे यकीन नहीं है कि मैं आपको समझता हूं, कुछ कोड अच्छा होगा। '(2): 'आप एक्शन विधियों पर प्राधिकरण विशेषताओं को जोड़ सकते हैं। – gideon
आप विशेषता का अपना संस्करण बना सकते हैं। http://stackoverflow.com/questions/746998/override-authorize-attribute-in-asp-net-mvc – Tx3
जी, हर कोई आपको समझ में नहीं आता :)। मैं समझता हूं, लेकिन मैं एक समाधान चाहता था क्योंकि मेरे पास एक ही समस्या है। क्या आपको इस दौरान कुछ मिला है? –