开发者

ASP.NET/URL Rewriting in a development environment

开发者 https://www.devze.com 2022-12-16 06:35 出处:网络
This is a general question about dealing with URL Rewriting in a development environment. I\'m developing a CMS to learn ASP.NET/C#, and I will of course need to implement URL Rewriting. This techniqu

This is a general question about dealing with URL Rewriting in a development environment. I'm developing a CMS to learn ASP.NET/C#, and I will of course need to implement URL Rewriting. This technique is known to me since I've been using with PHP for several years. However in PHP, you can have a local HTTP server, modify the PHP content directly, refresh the page and see the results. Of course in ASP.NET it's not exactly the same, since you need to compile and then publish the code.

The problem I have is that I need to check the URL Rewriting-friendly links my code will generate in my development environment - basically, make the ASP.NET Development Server compatible with URL Rewrite. Or maybe not.

My question really is: what is the best solut开发者_如何学JAVAion to do that? Use IIS/Apache2 (w/ Mono) for the development server?


Just enable IIS on your local machine, and then create a website and point it to the project directory of your website. That's by far the easiest way if you ask me.


As klausbyskov states, you could indeed set up IIS on you development machine and work directly on there:

Depending on your platform, it's probably easiest to have your project files under the wwwroot folder in IIS, then either create a new site pointing at that, or make sure that you've configured it as an Application in IIS. Just tell Visual Studio to use a "Local IIS Web Server" in the project properties. You could then use something like the IIS Url Rewrite Module to perform your routing.

Another option would be to add a reference to the System.Web.Routing library that was introduced in .NET 3.5 SP1 - there are a number of tutorials out on the web on using this with web forms as opposed to MVC. This would have the advantage that you'd be able to use the tools in the routing engine to generate the links correctly, and know that they would be handled correctly by the server - something you generally wouldn't get from an IIS module, where you'd be generating your links yourself, and having to ensure that the module was configured in the same way.


If you're developing I'll make a guess that you're doing it on Windows. The amount of hosts out there for Mono and Linux/Apache is fairly slim so it's best to get use to the IIS way of doing things.

For IIS Vista/Windows 7 you have a number of choices

  • One URL rewrite of many HTTP module for ASP.NET - this works very well if you only want rewritting on your ASP.NET pages. You can also infact map other filetypes since the IIS 7 changes
  • A URL rewriter ISAPI extension for IIS - faster than using the ASP.NET and more familiar to you if you're use to mod_rewrite.
  • Play about with ASP.NET MVC to get some instant results.

Scott Guthrie has a big post on it, and this question will help a lot.


If you configure your project as a "web site" instead of a "web application," then the web server will compile everything for you automatically whenever it changes; you won't have to do an explicit compilation unless you're changing code in a DLL that's used by the project.

This is easier with a local instance of IIS than Cassini, though, because Cassini doesn't seem to do quite as good a job at detecting changes and forcing restarts.


Try this

http://urlrewriter.codeplex.com/

It supports Apache syntax and URL Rewrite syntax in the Visual Studio development server.

0

精彩评论

暂无评论...
验证码 换一张
取 消