c# mvc get url parameter within an attribute
In my controller I have this "SomeAttribute" which validates an url. It checks whether the provided ID in the url is a valid ID and whether the category name is the relevant category name of the given ID.
[SomeAttribute]
public ActionResult SomeAction()
{
....
}
However, in my attribute I don't know how can I reach the current url parameters.
public SomeAttribute : ActionFilterAttribute {
public override void OnActionExecuting(ActionExecutingContext filterContext) {
string myurl = HttpContext.Current.Request["mystring"] // this does not work
}
}
So basically my question is, how can I reach the url of the curr开发者_运维问答ent context within an attribute?
Well in case you need url parameters within an attribute and you are using routing, this is the solution:
filterContext.RouteData.Values["mystring"]
精彩评论