简体   繁体   English

在非MVC ASP.NET Web窗体应用程序中使用System.Web.Mvc

[英]Use System.Web.Mvc in non MVC ASP.NET Web Forms Application

We are developing an ASP.NET Web Forms application with REST modelled URL, for which we are using Route tables in global.asax. 我们正在开发带有REST建模URL的ASP.NET Web窗体应用程序,为此我们在global.asax中使用Route表。 However, recently we came over a problem where the WebResource.axd and ScriptResource.axd files were getting routed as well. 但是,最近我们遇到了一个问题,其中WebResource.axd和ScriptResource.axd文件也被路由。 We wanted to use the RouteCollection.IgnoreRoute function. 我们想使用RouteCollection.IgnoreRoute函数。 However, since it in System.Web.Mvc, it would mean that we would need to reference that dll in a non MVC Web Forms application. 但是,由于它在System.Web.Mvc中,所以这意味着我们将需要在非MVC Web窗体应用程序中引用该dll。

Is it safe for us to continue with the approach. 对我们而言,继续采用这种方法是否安全? If anyone has a better way to ignore routes from within the Web Forms application please do share. 如果有人有更好的方法可以忽略Web窗体应用程序中的路由,请共享。 Please also note that the application has been extensively developed in Web Forms and moving to MVC at the current stage is not feasible. 还请注意,该应用程序已经在Web窗体中进行了广泛开发,并且在当前阶段转移到MVC是不可行的。

For web forms you need to use System.Web.Routing 对于Web表单,您需要使用System.Web.Routing

Put this is Global.asax 把这是Global.asax

void RegisterRoutes(System.Web.Routing.RouteCollection routes)
{
    routes.Ignore("{resource}.axd/{*pathInfo}");

    routes.MapPageRoute(
       "Home",      // Route name
       "WWWWWW",      // Route URL
       "~/Default.aspx" // Web page to handle route
    );
}

Did you know you could safely run an ASP.NET Web Forms and MVC application combined? 您是否知道可以安全地运行ASP.NET Web窗体和MVC应用程序的组合? Here are some links: 以下是一些链接:

Also, you can just use URL routing in ASP.NET 4 applications, as Registered User pointed out above. 另外,正如注册用户在上面指出的那样,您仅可以在ASP.NET 4应用程序中使用URL路由。 Read more about it here: http://weblogs.asp.net/scottgu/archive/2009/10/13/url-routing-with-asp-net-4-web-forms-vs-2010-and-net-4-0-series.aspx 在此处了解更多信息: http : //weblogs.asp.net/scottgu/archive/2009/10/13/url-routing-with-asp-net-4-web-forms-vs-2010-and-net- 4-0系列.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM