ASP.NET MVC : Response.Redirect(url, TRUE) does not stop request processing -
I have a way decorated with two custom Akshnfiltr Attribute
[RequiresAuthentication ( order = 1)] [ToonAction (order = 2)] Public ActionResult browse (...
RequiresAuthentication inside, it is OnActionExecuting I: line is executed, and the logic is all expected. The problem is that the above line is set After Padit, I would execute the next feature (Akshnfiltrativet), such as redirect Q: to make the request handler else do I need to do RequiresAuthentication
has been characterized
filterContext.HttpContext.Response.Redirect (loginUrl, true);
P> This is a complete method:
Public override zero on-one integration (Action Accepting Contact Filter Context) {// Redirect if not certified var identity = filterContext. HttpContext.User.Identity; If (! Identities .IsAuthenticated) using the current URL {// redirect string redirection Krenonsift = Filtrcontekst. HTTPPTXT request. Url.path endowy; // Bejen- URL to log on page String = Stringkformet ( "return url = {0}", Reedronsut); String login url = formatting.login url + redirectional; FilterContext.HttpContext.Response.Redirect (loginUrl, true); // filterContext.Result = new HttpUnauthorizedResult (); // filtercontext Hpptex response. Status code = 0x191; }}
You want to set the result in filter results on the redirect result, do not A redirect on feedback.
filterContext.Result = new RedirectResult {Url = loginUrl}; Edit: As @Hunter Daily suggests that if it works for you, instead of using a better mechanism AuthorizeAttribute. If you have an authentication / authorization scenario, for which AuthorizeAttribute does not work, it may be better to obtain your custom attribute instead of the more common ActionFilterAttribute, in any event, set the results instead of directly contacting the correct technique response To do. I have also got a sample of code on my blog.
Comments
Post a Comment