[AuthenticateUser] public class HomeController : Controller {
How to remove authentication for an action named List? Please inform ...
Custom filter modification as shown below. I also inherited the FilterAttribute call. Please inform about
public class AuthenticateUserAttribute: FilterAttribute, IAuthenticationFilter { public void OnAuthentication(AuthenticationContext context) { if (this.IsAnonymousAction(context)) { } if (user == "user") { // do nothing } else { context.Result = new HttpUnauthorizedResult(); // mark unauthorized } } public void OnAuthenticationChallenge(AuthenticationChallengeContext context) { if (context.Result == null || context.Result is HttpUnauthorizedResult) { context.Result = new RedirectToRouteResult("Default", new System.Web.Routing.RouteValueDictionary{ {"controller", "Home"}, {"action", "List"}, {"returnUrl", context.HttpContext.Request.RawUrl} }); } } }
The following error code is generated in the code below: Error 1 The best overloaded method match for 'MVC5Features.Filters.AuthenticateUserAttribute.IsAnonymousAction (System.Web.Mvc.AuthorizationContext)' has some invalid arguments c: \ users \ kirupananthan.g \ documents \ visual studio 2013 \ Projects \ MVC5Features \ MVC5Features \ Filters \ AuthenticateUserAttribute.cs 16 17 MVC5Features Error 2 Argument 1: Cannot convert from "System.Web.Mvc.Filters.AuthenticationContext" to "System.Web.Mvc.AuthorizationContext" c: users \ kirupananthan.g \ documents \ visual studio 2013 \ Projects \ MVC5Features \ MVC5Features \ Filters \ AuthenticateUserAttribute.cs 16 40 MVC5Features
if (this.IsAnonymousAction(context))
source share