I have working ASP.NET MVC 4 project. I want to add to this MVC project 2 .aspx
pages of another WebForms project. I have several questions:
- Where should I copy this
.aspx
files and how should I config my routes? - How should I tell this
.aspx
pages to use~/Shared/_Layout.chtml
as a master page? - Additionally this .aspx pages uses .ascx controls. Where should I store them?
- How should I modify web.config file?
I have looked at the links posted in this question, but they seemed to be outdated. A lot of the links explain how to add MVC to WebForms, but I am looking for all the way around.
Any useful links would be appreciated. Thanks!
The solution:
As it turned out, adding .aspx pages to the existing MVC project is an even easier task to accomplish than adding mvc to .aspx. The most interesting thing for me was to find out that both webforms and MVC, in the scope of one project share one runtime on IIS.
So what I did:
The following code provides information how to implement RenderPartial method in WebForms:
Add it to codebehind.cs of your .aspx page. Then you can call it from the webforms like this:
Since I had only the 'menu' shared among all my pages, I added it to the partial View, then called it in _Layout.chtml
and in MasterPage.Master like this:
That is all there is to it. As a result my _Layout.chtml and MasterPage.Master use the same shared partial views. And I can acess .aspx pages simply by navigating on them. If you have some issues with routing system, you can add
routes.IgnoreRoute("{resource}.aspx/{*pathInfo}");
to your routeConfig in App_Start.Sources I used:
I hope it will help somebody later on.