【发布时间】:2015-08-27 00:05:06
【问题描述】:
我正在尝试为“已收到”的错字准备 301 重定向
我正在努力寻找从动作和控制器名称中获取 url 的方法。
我知道 UrlHelper.Action,但它在 Global.asax 中不存在。我如何获得此方法的访问权限?:
// Add permanent redirection for retired pages (Application_BeginRequest())
if (HttpContext.Current.Request.Url.LocalPath.ToLower().StartsWith("/blah/listrecieved"))
{
HttpContext.Current.Response.RedirectPermanent(/*Need url generated from action and controller*/);
}
或者我已经创建了一个路由,如果我应该这样获取字符串,这也很好,但我不确定如何:
routes.MapRoute(
name: "blah-list-received",
url: "blah/list-received",
defaults: new { controller = "Blah", action = "ListReceived" }
);
例如,它可能看起来像这样:
// Add permanent redirection for retired pages
if (HttpContext.Current.Request.Url.LocalPath.ToLower().StartsWith("/blah/listrecieved"))
{
HttpContext.Current.Response.RedirectPermanent(routes.GetUrl( "blah-list-received" ) );
}
【问题讨论】:
标签: c# routing asp.net-mvc-5