In my application, key query string parameter can be used to grant access to certain actions/views.
Now I want all ActionLinks and Forms to automatically in
You can do it with routes but you need a bit more infrastrcuture. Something like this
public class RouteWithKey:Route
{
//stuff omitted
public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
{
values.Add("key", requestContext.HttpContext.Request.QueryString["key"]);
var t = base.GetVirtualPath(requestContext, values);
return t;
}
}
Of course you'll need to retrieve the key from the request params and handle the case where key is the second parameter in the query, but this apporach will add automatically the key to every utel constructed via the normal as.net mvc helpers
I just happen to use a custom route for an application, for a different purpose but I;ve tested with the code above and it adds the parameter, so at least in my project seems to work properly.