简体   繁体   English

Visual Studio C#中的URL重写

[英]URL Rewriting in visual studio c#

I have a couple of questions with regards to implementing URL Rewriting in Visual Studio 2008 关于在Visual Studio 2008中实现URL重写,我有几个问题

  • I am currently using Intelligencia.UrlRewriter to implement URL rewriting in CS 2008. However the rewrite rules are a little different as compared to the IIS7 rewrite rules.Is there a way we can use the same rules while debugging in VS2008 and then employ the same rules while using on IIS7. 我目前正在使用Intelligencia.UrlRewriter在CS 2008中实现URL重写。但是,与IIS7重写规则相比,重写规则有所不同。有没有一种方法可以在VS2008中进行调试时使用相同的规则,然后采用相同的规则IIS7上使用规则。

  • What is the best way to ignore images, css and js files from the rewriting rules.Is this possible with Intelligencia.UrlRewriter. 从重写规则中忽略图像,css和js文件的最佳方法是什么?这可以通过Intelligencia.UrlRewriter实现。

  • Are there any better methods? 有没有更好的方法?

    Thank You, 谢谢,

Kushal, 库沙尔,

Yeah you could do a couple of things. 是的,您可以做几件事。 Personally I would pick one and stick with it. 我个人会选择一个并坚持下去。 If you want to go Intelligencia, then your rules will work in the built-in debugger as well as IIS7 in Integrated Mode. 如果要使用Intelligencia,则您的规则将在内置调试器以及IIS 7的“集成模式”下运行。 If you want to use the rewrite rules extension, then install it in your local IIS7 http://www.iis.net/download/URLRewrite , then setup a new website in your local IIS pointing to the web root of your project. 如果要使用重写规则扩展,则将其安装在本地IIS7 http://www.iis.net/download/URLRewrite中 ,然后在本地IIS中设置一个指向项目的Web根的新网站。 Edit your hosts file and point the domain host header of your site to your local IP. 编辑您的主机文件,然后将站点的域主机标头指向本地IP。 You can edit the properties for your web project and select Custom Server for your debugger and paste the host header for your local site in there. 您可以编辑Web项目的属性,并为调试器选择“自定义服务器”,然后将本地站点的主机头粘贴到其中。 This way you're running IIS7 for dev and prod. 这样,您就可以为开发和生产运行IIS7。

For ignoring static files like js and css from the Intelligencia use this rule at the top of your rule list: 要忽略Intelligencia中的js和css之类的静态文件,请在规则列表的顶部使用此规则:

<rewrite url="^(/.+(\.gif|/.+\.png|\.jpg|\.ico|\.pdf|\.css|\.js|\.asmx|\.axd|\.flv|\.swf)(\?.+)?)$" to="$1" processing="stop" />

The only other thing I can think of is to setup a post-build task that would run a script to read Intelligencia rules, then convert and write them as IIS rewite rules. 我唯一想到的另一件事是设置一个构建后任务,该任务将运行脚本以读取Intelligencia规则,然后将其转换并编写为IIS重演规则。

I would recommend using URL Rewrite for that, http://www.iis.net/download/URLRewrite and for development use IIS Express ( http://learn.iis.net/page.aspx/868/iis-developer-express-overview/ ) which comes with URL Rewrite integrated and you can set up and use it with VS 2008, see: How to configure Visual Studio 2008 to use IIS Express? 我建议为此使用URL Rewrite, http: //www.iis.net/download/URLRewrite并为开发使用IIS Express( http://learn.iis.net/page.aspx/868/iis-developer-express -overview / )(集成了URL Rewrite),并且可以在VS 2008中进行设置和使用,请参阅: 如何配置Visual Studio 2008以使用IIS Express?

The best thing is that you will have all the features (not only URL Rewrite), like Request Filtering, Failed Request TRacing, etc, that you will have when you deploy to the server and be completely ready to deploy. 最好的事情是,您将拥有部署到服务器并完全准备就绪时将拥有的所有功能(不仅包括URL重写),例如请求过滤,失败的请求跟踪等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM