Adding iis 7.5 rewrite rules from asp.net 3.5 application - c#

We are interested in adding url rewrite rules programatically from our c#\asp.net 3.5 application to our iis 7.5 web server.
Is there any API for this, or should we just write into the web.config?
Some background: we are developing a hosted CMS that will host multiple websites, each website with it's own custom url rewrites.
This means that we should also be able to handle hundred thousand url rewrite rules - if you are aware of any limitaion of the IIS url rewrite module regarding this - please say so!
important note: we can't use the RewritePath c# method because we are rewriting to different application(seperate dlls with seperate web.config files).
Thanks in advance,
Eytan.

Related

Using WCF for dynamically generated IIS rewrite rules in web.config

I've got a ASP.NET MVC 4 client for which I would like to load the IIS rewrite rules dynamically from a CMS. The set up is IIS7.5 with URL rewrite module 2 and .NET 4.5.
I've been reading the article, 'http://www.iis.net/learn/extensions/url-rewrite-module/using-custom-rewrite-providers-with-url-rewrite-module' but I would like to implement this using WCF instead of SQL Server. Does anyone know how to implement this?
The idea is that I can then control all rewrite rules from a CMS system instead of having to modify the web.config manually.
Or is it possible to use a dynamic config source in the web.config which points to and reads from a WCF service?

HttpModule to catch all extensions

I've created HttpModule in ASP.NET, and configured it successfully.
My problem is, the module is called only when I give the URL extension (i.e. aspx), if i dont put any extension, the module won't be called.
How can I solve this?
thanks
The problem is that the request is not being handled by ASP.Net - IIS 6 and below only invokes ASP.Net when it encounters a filename that it associates with ASP.Net, such as an .aspx or .axd file extension.
This is similar to the problem faced when attempting to deploy MVC applications to IIS 6 or below (IIS fails to route the requests to ASP.Net), and the solutons are also similar - you can either individually map every extension you wish to see handled to aspnet_isapi.dll the ASP.Net handler (which still won't work for URLs that don't have extensions), or you need to use a wildcard mapping to tell IIS to direct all requests to ASP.Net - note that this will include images and other static files which might get handled less efficiently than normal.
The article Deploying ASP.NET MVC to IIS 6 discusses the solutions for deploying MVC applications to IIS 6 - this discusses potential solutions with greater detail than I have space for here.

Implement restful url in .net where service is implemented using IHTTPHandler

I want to implement a restful service in ASP.NET. I want it to be compatible with .Net 2.0 and IIS 5+. I am constrained to not use ASP.NET MVC or REST starter kit. By reading on internet I have learned that it can be implemented using HTTPHandlers. The problem is, the request will come in as a POST request. And I want to URL to be like:
http://abc.com/MyService/MyMethod1/
and
http://abc.com/MyService/MyMethod2/
Any workarounds for this?
Thanks,
Vamyip
Your best option is to use URL Rewriting. This is non-trivial in IIS5. The methods I know of are as follows:
Method 1 - ISAPI filter
These are low-level modules that allow you to manipulate the incoming request. Programming one of these is hairy and tough to debug. If you go this route, you are better off using one that has already been built like ISAPI_Rewrite.
Method 2 - IHttpModule
These are managed ASP.Net modules that are easy to add/remove from your application. Again, you are better off using a pre-built component like UrlRewriter.NET. The issue with using one of these, (as BrainLy mentions), is that you have to configure IIS 5 to map all incoming requests to ASP.Net as follows (link):
Open Up IIS and Navigate to the “Home Directory Tab”
Select “Configuration”
Click “Add” and enter “C:\WINNT\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll” in the Executable box. For the file extension, enter “.*”. Finally, make sure that “Check that file exists” is not checked.
One interesting thing to note is that ASP.Net is itself an ISAPI module :)
Once you are able to manipulate URLs using one of these tools, you can easily rewrite the RESTful urls to be handled by your default.aspx page (or whatever handler you choose to use).
If you can allow the restriction of only IIS 7.0 and above you could use URL Rewrite http://www.iis.net/download/URLRewrite to do that pretty easily.
Can I ask why is it that you need to support IIS 5+? That is an 11 year old technology that hopefully people will move out of those platforms in favor of more recent versions. Also keep in mind support for some of those platforms is ending pretty soon.
If the concern is developers running Windows XP I would point out that IIS Express includes version 7.5+ functionality and is available for all platforms Windows XP and above.
I think this will be difficult to do because IIS 5 will not let you handle non ASP.NET file extensions without some additional configuration in IIS. That means you are limited to URLs ending in .aspx etc. To handle URLs like those in your examples you need to map ASP.NET to handle all URLs in IIS, implement some type of URL rewriting, or introduce some kind of hacky 404 redirection.
Once you have the correct mapping in place you can wire up an IHttpHandler, but you will have to parse the incoming request yourself to work out which is /MyService/MyMethod1/ and which is for /MyService/MyMethod2/. If your methods are simple then it is easy to do this with a regular expression.
You should start with a simple handler like this one.

Deploy ASP.NET MVC application in IIS

I have planned to develop a web application using MVC, can any one suggest me the how easy to deploy the application on the IIS?
And also let me know the steps to that.
regards,
Satish
Just publish your application either to your server directory or locally and copy it to the the destination server. Make sure your server is configured for MVC, see below:
Using ASP.NET MVC with Different Versions of IIS
Server installation options for ASP.NET MVC 2
as rick says, and also, make sure (if IIS6) to use wildcard mapping - this needs to be added in the IIS control panel. again, our old friend google should throw up plenty of options on doing this. if you're under shared hosting, you can request it and most are happy to add it.
jim

Using SEO friendly URLs in ASP.NET

I am in a situation where I want to restructure my site's urls. That is I have a page that lists the article names (with each article name as a link). As shown below:
ARTICLE1
ARTICLE2
ARTICLE3
Now if I click on an article I want the url to be as follows:
www.domain.com/ArticleID/name-of-the-Article
The term your looking for is "url rewriting" or "routing".
I think the easy way will be to use the ASP.NET MVC routing, it works with Webforms too:
Using Routing With WebForms
Routing with ASP.NET Web Forms
I think you're looking for URL Rewriting, I'd also recomend UrlRewritingNet.
Other possibilities that have worked well:
If your site is hosted on Windows Server 2008, you can use the Microsoft URL Rewrite Module for IIS 7.0.
A nice tool for older servers is Isapi Rewrite (look here - there's a free light version), very similar to Apache style mod_rewrite. May be a problem in shared hosting environments unless the provider is willing to install an Isapi dll.

Categories

Resources