tags:

views:

131

answers:

3

I have the folowing scenario:

www.somedomain.com -> this points to a folder on a shared host, say /MyFolder1 www.otherdomain.com -> this points to another folder on the same shared host, say /MyFolder2

With asp.net mvc my urls get mapped to:

www.somedomain.com/MyFolder1/Action www.somedomain.com/MyFolder2/Action

I (obviosly) dont't want to have "MyFolder1" and "MyFolder2" on my URLs. How do i solve this on asp.net MVC?

I want to have:

www.somedomain.com/Action www.somedomain.com/Action

But i need to keep the subfolders on IIS (or some other solution that allows me to have two sites, with different domains on the same hosting).

Help is very much appreciated.

Thanks

+1  A: 

The best way to handle this IMO is to use rewriting at the IIS level. I just did this on a site using IIS 7 URL Rewrite. If you don't have this module installed on your host provider, you can try to use one of the other URL rewriting tools. But, for example on DiscountASP you can use IIS 7 URL rewrite.

First you need to point all your domains to your current site. Then when you download the tool: http://blogs.iis.net/bills/archive/2008/05/31/urlrewrite-module-for-iis7.aspx, it provides a GUI for editing the rules. Ultimately the rules are placed into your web.config file. You want your rules to look something like this:

    <rewrite>
        <rewriteMaps>
            <rewriteMap name="otherdomain" />
        </rewriteMaps>
        <rules>
            <rule name="otherdomain" stopProcessing="false">
                <match url=".*" />
                <conditions>
                    <add input="{HTTP_HOST}" pattern="otherdomain.com" />
                </conditions>
                <action type="Rewrite" url="/site_folder/otherdomain/{R:0}" />
            </rule>
        </rules>
    </rewrite>

If you are using ISAPI rewrite, I'll probably have that one soon as well for another host that I'm using that doesn't support IIS rewrite

Trevor de Koekkoek
A: 

My hosting provider is using IIS 6 with ISAPI_Rewrite.

It works fine, www.somedomain.com/MyFolder1/Action becomes www.somedomain.com/Action as i want on the entry page. But all Url.ActionLink() maps again to www.somedomain.com/MyFolder1/Action which i don't want.

A: 

The easiest thing to do would be to create a subdomain on the shared host. Something like app1.somedomain.com and app2.somedomain.com, the subdomain maps directly to the subdirectory where the application is and that becomes the root.

Tony Borf