Running MVC with exforming Webforms

I read, if not all articles about adding MVC 3 to existing web form sites. I made changes to the global asax web forms to support MVC, as well as changes to web.config. However, there are still some problems.

  • MVC 3 is greedy - by default it takes the root of the site, so to go to the root, I go to the input page for mvc, and not the web forms page that I want. To be clear when navigating to the root, I want it to go to mysite.com/default.aspx. To fix the root of the site, I add

    routes.MapPageRoute ("SiteRoot", "," ~ / Default.aspx ") However, then it breaks the MVC URLs, so I end up with spoiled URLs like

    http: // localhost: 86 / default? action = Index & controller = Blog How can I fix this so that the root of the site goes to webforms default.aspx and still has my correct MVC URLs?

  • MVC 3 breaks a piece of HttpHandlers, which uses a web form. In particular, I use a handler to add a large number of future headers to images and a resource handler to combine style sheets and javascript files. The explicit presence of any route in RegisterRoutes splits these handlers so that style sheets are not loaded through the resource handler, and I lose the far future, and there is an httpcompression module that also stops working. So, how do I support httphandlers and modules for web forms, while maintaining the routes for the MVC 3 part of the site?

I didn’t see these 2 questions, so that anyone would contact different blogs about mixing MVC3 and web forms.

Oh, and I have routes.IgnoreRoute ("{resource} .aspx / {* pathInfo}") in global.asax. The resource handler uses the aspx file extension, so I would have thought that with this exception globally, that hanlder would work, but I think not.

Another possibility I know is to create a folder inside the wbeforms website and run it as my own starting point for the application, but in the end I get a url that I really don't want, for example site.com/blog/blog/index, where 1 The 2nd blog is a folder that works as a native point of the application, and the second blog is a controller.

+4
source share
2 answers

The best solution I can find is not to mix MVC 3 with an existing web form site. Instead, set the MVC directory as your own starting point for the application, and then run MVC from this folder so that it and the existing webforms application do not completely know each other. Thus, the resource handler and httpmodules and other handlers still work on the website. And so the domain root goes to webforms default.aspx, not the default MVC. Also, I don’t need to insert this entry into global.asax, which in turn screwed up the mvc 3 URLs. The next problem was to figure out the urls so that I did not have url lke blog / blog / post /1. To fix this, I changed the html action link to

@Html.ActionLink(item.PostTitle, "Post", New With {.id = item.PostId}, Nothing) 

And then make changes to global.asax - change the default route (just delete {controller}:

 routes.MapRoute( _ "Default", _ "{action}/{id}", _ New With {.controller = "Blog", .action = "Index", .id = UrlParameter.Optional}, New String() {"RiderDesignMvcBlog.Core.Controllers"}) 

So now instead of blog / blog / index or blog / blog / post / 1, I get the correct clean URL without a duplicate blog in url - blog / post / 1

+1
source

I suggest you change the extension of your handler as a true handler, .ASHX and ignore them instead.

0
source

All Articles