问题描述
我有一个问题,由此我想不同的方式显示的图(不同的母版页),这取决于它是从哪里来的,但不知道从哪里开始...
I have a problem whereby I want to display a view differently (a different master page), depending on where it came from, but don't know where to start...
我有几个路线,可赶上包含不同结构的各种不同类型的网址。
I have several routes which catch various different types of urls that contain different structures.
在下面的code段,我有一个产品路线,然后我有一个合作伙伴站点的路由也可以去一个产品页,但让我们说,这个合作伙伴是百事可乐,他们希望自己的品牌上母版页,而不是我们自己的默认样式。可以说,我去。这应该去相同的URL 和PartnerRedirect将能够通过(产品/ cola.htm,在这种情况下)翻译的URL和通配符到一个控制器动作来处理基于通配符的URL,并转发用户,(但简单地改变母版页视图)。
In the code snippet below, I have a product route, and then I have a partner site route which could also go to a product page, but let's say that this partner is Pepsi, and they want their branding on the master page, rather than our own default styling. Lets say I go to products/cola.htm. This should go to the same url as partners/pepsi/products/cola.htm, and the PartnerRedirect would be able to handle the url based on the wildcard, by translating the url wildcard (in this case, "products/cola.htm") into a controller action, and forward the user on, (but simply change the master page in the view).
routes.MapRoute(
"Product",
"products/{product}.htm",
new { controller = "Product", action = "ShowProduct" }
);
routes.MapRoute(
"ProductReview",
"products/{product}/reviews.htm",
new { controller = "Product", action = "ShowProductReview" }
);
routes.MapRoute(
"Partner",
"partners/{partner}/{*wildcard}",
new { controller = "Partners", action = "PartnerRedirect" }
);
这可能吗?如果是这样,怎么样?
Is this possible? And if so, how?
提前非常感谢。
推荐答案
在你的合作伙伴的控制器你为什么不设置一个cookie,表示要显示它的合作伙伴,然后重定向到路由的通配符部分。这样,你可以显示所有后续页面访问量相同的合作伙伴布局。
In your partners controller why don't you set a cookie that indicates which partner you want to show, and then redirects to the wildcard section of the route. That way you can show the same partner layout for all subsequent page views.
我不知道如果这是你在找什么,但它可能是一种选择。
I don't know if this is what you're looking for, but it might be an option.
这篇关于重定向到控制器(但使用不同的主机)使用通配符包罗万象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!