Dear all,
I'm trying to get a URL from my routes table. Here is the method.
private static void RedirectToRoute(ActionExecutingContext context, string param)
{
var actionName = context.ActionDescriptor.ActionName;
var controllerName = context.ActionDescriptor.ControllerDescriptor.ControllerName;
var rc = new RequestContext(context.HttpContext, context.RouteData);
string url = RouteTable.Routes.GetVirtualPath(rc, new RouteValueDictionary(new { actionName = actionName, controller = controllerName, parameter = param })).VirtualPath;
context.HttpContext.Response.Redirect(url, true);
}
I'm trying to map it to. However RouteTable.Routes.GetVirtualPath(rc, new RouteValueDictionary(new { actionName = actionName, controller = controllerName, parameter = param })) keeps giving me null. Any thoughts?
routes.MapRoute(
"default3", // Route name
"{parameter}/{controller}/{action}", // URL with parameters
new { parameter= "parameterValue", controller = "Home", action = "Index" }
);
I know I can use redirectToAction and other methods, but I would like to change the URL in the browser with new routedata.