Asp.net MVC 4 RedirectToAction - prePEND域 [英] Asp.net MVC 4 RedirectToAction - prepend domain
问题描述
我需要prePEND域在RedirectToAction进行重定向,所以它相对的不是,但绝对URL。这怎么可能实现呢?
I need to prepend a domain to the redirect performed in RedirectToAction, so it's not relative, but an absolute url. How can this be accomplished?
编辑:我要补充一点的详细信息:
这是一个多租户应用程序,允许为客户设置proxydomains。所以,我需要所有的URL要经过代理。因此,一个actionredirect,这将是: http://domainX.com/Question/$p$pview/ 640328 需要通过 http://domainY.com/SUBDOMAIN/Question / preVIEW / 640328
I'll add a bit more information: It's a multitenant application that allows for clients to setup proxydomains. So I need all the urls to go through the proxy. So an actionredirect that would be: http://domainX.com/Question/Preview/640328 needs to go through http://domainY.com/SUBDOMAIN/Question/Preview/640328
推荐答案
这不能使用它自己RedirectToAction完成。但是, UrlHelper.RouteUrl方法可用于产生使用特定的主机名绝对URL。
This can't be done using RedirectToAction on it's own. However, the UrlHelper.RouteUrl method can be used to generate absolute URLs using a specific host name.
您只需要使用UrlHelper.RouteUrl,然后使用Redirect方法执行重定向生成的URL。
You simply need to generate the URL using UrlHelper.RouteUrl, then perform the redirect using the Redirect method.
如果您知道路由名称,使用类似以下内容:
If you know the route name, use something like the following:
var routeValues = new RouteValueDictionary(new { id = 12345 });
string url = Url.RouteUrl("Products.Show", routeValues, "http", "www.domainname1.com");
return Redirect(url);
如果你想生成基于控制器名称和动作的URL,使用以下命令:
If you want to generate the URL based on the controller name and action, use the following:
var routeValues = new RouteValueDictionary(
new { controller = "Products", action = "Show", id = 12345 });
string url = Url.RouteUrl(null, routeValues), "http", "www.domainname1.com");
return Redirect(url);
上面的每条记录将重定向到一个绝对URL如 http://www.domainname1.com/products / 12345
注意UrlHelper的一个实例,通过内置的 Controller.Url 属性)。
Note that an instance of UrlHelper is available within controller code via the built-in Controller.Url property).
这篇关于Asp.net MVC 4 RedirectToAction - prePEND域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!