Original address: http://www.cnblogs.com/snowdream/archive/2009/04/17/winforms-in-mvc.html
ASP. NET MVC and WebForm each have their advantages, and we may need to use both ASP. NET MVC and WebForm. This article describes how to use WebForm in an ASP. NET MVC project.
Create a new folder named WebForms to hold WebForm, and add a Web Form file Demo.aspx as a demo.
Demo.aspx simply output a word "It's a WebForm."
The key step is the routing settings. If you want to webforms this folder name as part of the URL, that is, the normal WebForm application to access this demo.aspx, then simply ignore the routing rule.
Add the following code to the RegisterRoutes method of the Global.asax.cs file
Ignoring routes to the WebForms path
Routes. Ignoreroute ("Webforms/{weform}");
Results:
If you want the URL to be more friendly or do not appear webforms this folder name, it is necessary to write a class to inherit Iroutehandler.
1public class Webformsroutehandler:iroutehandler
2{
3 private String pageName = String. Empty;
4
5 public IHttpHandler Gethttphandler (RequestContext requestcontext)
6{
7//Get the page parameter from the URL
8 PageName = requestContext.RouteData.GetRequiredString ("page");
9
10//Create an instance
11//To access WebForms page according to page parameter stitching into similar/webforms/page.aspx address
IHttpHandler hander = Buildmanager.createinstancefromvirtualpath ("/webforms/" + this.pagename+ ". aspx", typeof (Sy Stem. Web.UI.Page) as IHttpHandler;
13
Hander return;
15}
16
+}
Then add a new routing rule to the Global.asax.cs file
Add a route that is handled with Webformsroutehandler
Where the portion of {page} in the URL is used as a parameter in Webformsroutehandler
Routes. ADD (New Route ("Web/{page}", New Webformsroutehandler ()));
When the path matches web/{page}, a custom class is used to handle the request, such as a URL such as Web/demo or WEB/DEMO1, which will match the route
Sample Download