请帮助澄清以下内容. 我有一个项目,其中我要重定向其中具有查询字符串值的页面.例如: www.codeproject/product.aspx?bookid=5&bookname=23 现在,我想在我的项目中实现URL路由技术.这样,URL应如下所示: www.codeproject/Product/5/23 我已经在global.asax文件中创建了路由定义.出于测试的目的,当我运行项目并自己更改旧网址时,网址是"href =" www.codeproject/product.aspx? bookid = 5& bookname = 23"到我所需的网址"www.codeproject/Product/5/23".效果很好. 但我的问题是: 我的旧网址仍然很丑陋,其中包含查询字符串值.我希望它们自动显示为"www.codeproject/Product/5/23"或"www.codeproject/Product/7/34< 我不想一直更改网址.我希望该网址自动以上述格式显示. 我现在是否需要将server.redirect的所有c#代码更改为所需的格式,或者它们是否是将丑陋的url转换为美观,有意义且可读的格式的任何其他技术. 非常感谢, Jass
Hi, Please help in clarifying the following. I have a project in which I am redirecting pages having Query String values in it. eg: www.codeproject/product.aspx?bookid=5&bookname=23 Now, I want to implement URL Routing technique onto my project. So that the URL should look like the following: www.codeproject/Product/5/23 I have created Route Definition in global.asax file.For the purpose of testing, When I run my project and change the old by myself URL from "href="www.codeproject/product.aspx?bookid=5&bookname=23 " to my required url " www.codeproject/Product/5/23 ". It works fine. But My question is : My old url still comes up ugly having Query String values in it. I want them to automatically appear like " www.codeproject/Product/5/23 " or " www.codeproject/Product/7/34 " I don''t want to change the url all the time. I want the url to appear in the above format automatically. Do I need to change all the c# code of server.redirect to the required format now or their is any other technique which transforms the ugly url to good looking, meaningful and readable format. many thanks, Jass
推荐答案结帐: IIS URL重写 [ ^ ].
是新的吗?项目?您可能想尝试使用MVC,它具有您想要的所有功能. is this new project? you might want to try MVC instead, it has all that you wanted.
您好, 对于此问题,我建议您使用URL重写器.正如您在我的博客文章中看到的那样,这非常简单: blog.dotnetcorner.ch/post/2011/03/30/How-to-Create-an-easy-and-flexible-URL-Rewriter.aspx [ ^ ]. 使用URL重写器的困难在于,您始终需要知道自己有两个不同的URL,并且永远不会给出任何内部(重写)URL.因此,如果创建链接,则不必担心创建用户友好" URL,而不仅仅是写出当前的Request.Url. 希望对您有所帮助,祝您编程愉快! :) 最好的问候, 停止 Hello, For this problem, I would recommend that you use a URL rewriter. It is quite easy, as you can see in my blog-post here: blog.dotnetcorner.ch/post/2011/03/30/How-to-Create-an-easy-and-flexible-URL-Rewriter.aspx[^]. The difficulty by using a URL Rewriter is, that you always need to know that you have two different URLs and that you never give out any internal (rewritten) URLs. So if you create a link, you have to concern about creating a "user-friendly" URL and not just write out the current Request.Url. Hope this helps, happy coding! :) Best regards, Stops
更多推荐
如何将值传递到URL?
发布评论