views:

34

answers:

1

Hello, I have an ASP.NET Web Forms Application in migration process to ASP.NET MVC 1. Urls are as follows:

hxxp://domain/Default.aspx (WebForms)

hxxp://domain/mvc/Controller/Action (MVC)

(hxxp because stackoverflow thinks they are links and prevents me from posting so many)

"mvc" is another application inside my Web Site in IIS7.

I now need to be able to do this:

hxxp://domain/subsiteName/Default.aspx (WebForms) hxxp://domain/subsiteName/mvc/Controller/Action (MVC)

Where 'subsiteName' can be anything and must be checked in runtime. I can't create directories for each subsiteName.

I thought of UrlRewriting, so /subsiteName/* rewrites to /*, but then I'd have to rewrite from WebForms to MVC.

I can't imagine a way to make a request to hxxp://domain/subsiteName/mvc/ ever be taken by the MVC application in this scenario.

Any ideas?

A: 

Here is how you would write the following in the Managed Fusion URL Rewriter, which uses the Apache mod_rewrite syntax:

I now need to be able to do this: hxxp://domain/subsiteName/Default.aspx (WebForms) hxxp://domain/subsiteName/mvc/Controller/Action (MVC)

RewriteRule /(.*)/Default.aspx   /$1/mvc/Controller/Action

However I assume that you don't already have all your directories set like this so you need some way of telling MVC that the subsiteName is a parameter or your methods. So what you would do in your routes is the following:

routes.MapRoute(
    "Default",
    "/{siteName}/mvc/{controller}/{action}",
    new { controller = "Home, action = Index }
);

That will take the rewrite path and merge it into the standard HomeController. Then for say the Index action you would have something like this:

public ActionResult Index (string siteName) { ... }

And then just handle siteName in a special way. Obviously this is over simplified example of how you can handle this, but if you want you can also handle this with a custom view engine, that routes to different templates depending on the site name. Or you can pull siteName out of the routes variable if you don't want to have it on every method.

Basically after you have the above setup, if that is really the structure you want, there is tons of ways you can handle this, you just have to find the one that is most easily used by your current code.

Nick Berardi
Actually, what I needed was to make hxxp://domain/subsiteName/mvc/Controller/Action rewrite to hxxp://domain/mvc/Controller/ActionI think I should have mentioned that the 'MVC' was an Application inside the same WebSite hosting the WebForms application, in order to share web.config files.I found that Managed Fusion didn't take the MVC URLs. It only logged accesses to *.aspx, maybe because it's an application domain solution.I solved my problem with Helios ISAPI_Rewrite module.Unfortunately it's not open source and the lite version does not support manual deploy.Thanks for the help man.
Fauna