Ali Jamal
Ali Jamal

Reputation: 840

Redirect To Link OnActionExecuting (ActionExecutingContext)

Salaamun Alekum I Want To Override

Controller.OnActionExecuting Method (ActionExecutingContext)

And Inside This Method I Want To RedirectTo WebPage Link How To Make It Possible

Example:

public class LicenseFilterAttribute : ActionFilterAttribute
{
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        ///Some Code Here
        Redirect("http://webpage.com"); ///Redirect to This Page 
        ///Rest Of The Code

Thank You Please Tell Me If You Require Further Details

Upvotes: 1

Views: 1118

Answers (1)

AaronH
AaronH

Reputation: 109

you're close but instead of the redirect try

filterContext.Result = new RedirectResult("http://www.webpage.com");

that's what I use anyways. Usually it's redirecting to my login page which would be on the same project so I would do something like

filterContext.Result = new RedirectResult(Url.Action("Index", "Login"));

edit: removed return statements, it's a void and you only need to set the redirect result not return it

Upvotes: 1

Related Questions