ASP.NET MVC中的重定向 [英] Redirection in ASP.NET MVC

查看:164
本文介绍了ASP.NET MVC中的重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

如何在 ASP.NET MVC 2 中从"http://www.website.com/ products/brand1 "开始的所有页面中实现URL重定向"http://www.website.com/产品/品牌2 "?这里的''brand1''''brand2''是参数.我知道如何在控制器中编写代码,但是在产品" 区域中有很多,因此我需要更有效的方法.

这是一个现有站点.
确实,我在一个产品"区域中有多个具有相同功能的品牌.所以我有以下链接:
http://www.website.com/products/adidas/addnewproduct
http://www.website.com/products/adidas/editproduct?id=345
http://www.website.com/products/adidas/admin/index
...
http://www.website.com/products/nike/addnewproduct
http://www.website.com/products/nike/editproduct?id=345
http://www.website.com/products/nike/admin/index

现在,我想从"adidas"重定向到"adidas_new".这意味着,当用户在浏览器中键入"http://www.website.com/products/adidas/addnewproduct"时,它将重定向到"http://www.website.com/products/adidas_new/addnewproduct"


预先感谢.

Hello everybody!

How to implement URL redirection in ASP.NET MVC 2 from all pages which start from ''http://www.website.com/products/brand1'' to ''http://www.website.com/products/brand2''? Here ''brand1'' and ''brand2'' are parameters. I know how to do it writing code in controllers but I have a lot of them in ''Products'' area therefore I need more efficient way.

This is an existing site.
Really I have one area ''Products'' where I have several brands with the same functionality. So I have the following links:
http://www.website.com/products/adidas/addnewproduct
http://www.website.com/products/adidas/editproduct?id=345
http://www.website.com/products/adidas/admin/index
...
http://www.website.com/products/nike/addnewproduct
http://www.website.com/products/nike/editproduct?id=345
http://www.website.com/products/nike/admin/index

And now I want to redirect from ''adidas'' to ''adidas_new''. It means when the user types ''http://www.website.com/products/adidas/addnewproduct'' in browser it redirects to ''http://www.website.com/products/adidas_new/addnewproduct''


Thanks in advance.

推荐答案




除了创建不同的视图(例如"http://www.website.com/products/brand1"或"http://www.website.com/products/brand2"),您还可以创建单个视图,例如http://www.website.com/products/brand?id=1并将"brandid"作为参数传递给查询strinf,您可以在控制器中处理查询字符串参数.

希望我在这里回答了您的问题.
Hi,

Instead of creating a different view like ''http://www.website.com/products/brand1'' or ''http://www.website.com/products/brand2'' you can create a single view something like http://www.website.com/products/brand?id=1 and pass the ''brandid'' as paramater in query strinf, you can handle the query string parameters in your controller.

I hope i answered you question here.


这篇关于ASP.NET MVC中的重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆