简体   繁体   中英

Figuring out what link a user clicked in ASP.Net MVC

I have 4 links a user can click with each one's destination being different but I have a Filter applied to each ActionResult in the Controller that runs a few checks and redirects them to a page with a required form. I am trying to figure out a way to capture what link was clicked and store it in Session so when the user lands on the page the filter redirects to I can create a link back the page s/he was intending to go to. I tried Request.UrlReferrer but that simple catches the URL for the page the user was on when s/he clicked the link.

Controller:

[NetGalFilter]
public ActionResult Transactions()
{
    return View();
}

Filter:

public class NetGalFilter : ActionFilterAttribute
{
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        var Controller = filterContext.Controller as Sprague.RTS.WebUI.Controllers.BaseController;

        if (HttpContext.Current.Session["HasConfirmed"] == null && Controller.TerminalUserData.IsNetGallonTerminal)
        {
            filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { controller = "DataEntry", action = "ConversionFactors" }));
        }

        base.OnActionExecuting(filterContext);
    }
}

You can use the HttpContext in filterContext . There you have the Request property which is of type HttpRequestBase and has the RawUrl to get the exact URL from the browser as well as other properties to get the parsed Action and Controllers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM