ASP.NET MVC和Web Forms在同一个Web应用程序中?

时间:2021-03-31 03:21:44

Has anyone successfully deployed ASP.NET MVC alongside Web Forms in the same application in a production environment? Were there any conflicts or gotchas you faced while doing so?

有没有人在生产环境中的同一个应用程序中成功部署ASP.NET MVC和Web Forms?这样做是否有任何冲突或陷阱?

Is it really as easy as shown here in practice? What about if you run a MVC using the Razor view engine alongside Web Forms?

这真的和实践中显示的一样简单吗?如果你使用Razor视图引擎和Web Forms一起运行MVC怎么样?

5 个解决方案

#1


10  

Mvc is build on top of asp.net as is webforms, so yes it's easy. Done it couple of times for conversion purposes

Mvc建立在asp.net之上,就像webforms一样,所以是的,它很容易。做了几次转换的目的

Maybe this url's could help you:

也许这个网址可以帮到你:

http://www.hanselman.com/blog/IntegratingASPNETMVC3IntoExistingUpgradedASPNET4WebFormsApplications.aspx

and

http://www.hanselman.com/blog/PlugInHybridsASPNETWebFormsAndASPMVCAndASPNETDynamicDataSideBySide.aspx

#2


3  

One gotcha is don't put your WebForms inside the Views folder. I haven't get figured how to make MVC leave those paths alone. None of the ignore routing instructions seems to work in this case and the WebForms throw 404s.

一个问题是不要将您的WebForms放在Views文件夹中。我还没想到如何让MVC独自离开这些路径。在这种情况下,忽略路由指令似乎都不起作用,WebForms抛出404。

Other than that WebForms works perfectly fine alongside MVC since MVC2.

除了MVC2以外,WebForms与MVC一起工作得非常好。

#3


2  

Has anyone successfully deployed ASP.NET MVC alongside Web Forms in the same application in a production environment?

有没有人在生产环境中的同一个应用程序中成功部署ASP.NET MVC和Web Forms?

I never mixed ASP.NET MVC and classic WebForms in the same application. I make them run in separate applications and communicate between them with standard HTTP techniques (query string parameters, form posts, cookies, ...).

我从未在同一个应用程序中混合使用ASP.NET MVC和经典WebForms。我让它们在单独的应用程序中运行,并使用标准HTTP技术(查询字符串参数,表单帖子,cookie,...)在它们之间进行通信。

Is it really as easy as shown here in practice?

这真的和实践中显示的一样简单吗?

Yes, it is as easy as that.

是的,就这么简单。

#4


2  

Check out scott hanselmans AddMvc3ToWebForms nuget package. I am using it and its working pretty great. I am using it to gradually convert my web forms app to mvc

查看scott hanselmans的AddMvc3ToWebForms nuget包。我正在使用它,它的工作非常好。我正在使用它逐步将我的Web表单应用程序转换为mvc

#5


2  

I've spent a lot of time over the past few months on this. Here are my observations.

过去几个月我花了很多时间在这上面。以下是我的观察。

The good/easy - Getting Webforms to call into MVC controllers - It was remarkably easy to stand up a new MVC3 project and drop Webforms pages into it. - I was able to move my <pages><controls></controls></pages> section into the /pages directory in a new web.config there

好/易 - 让Webforms调用MVC控制器 - 站起来一个新的MVC3项目并将Webforms页面放入其中非常容易。 - 我能够将 部分移动到新的web.config中的/ pages目录中

The dirty/difficult

  • Regarding the GUID

    关于GUID

    • Please note that the GUID has to be added at the front of the line for some reason... everytime I tried it failed. Until I stumbled on a post that insisted it be the before the others.
    • 请注意,由于某种原因,必须在行的前面添加GUID ...每次我尝试失败时。直到我偶然发现一个坚持它在其他人之前的帖子。

    • also I don't know what the difference is but I have a different GUID working... {E53F8FEA-EAE0-44A6-8774-FFD645390401}
    • 我也不知道有什么不同但我有一个不同的GUID工作... {E53F8FEA-EAE0-44A6-8774-FFD645390401}

  • getting the landing page to be Webforms caused ALL kinds of snags.

    使着陆页成为Webforms会导致各种障碍。

  • getting jQuery intellisense to play nicely with T4MVC
  • 让jQuery intellisense与T4MVC很好地配合

this is what I did to address that

这就是我为解决这个问题所做的工作

@if (System.Diagnostics.Debugger.IsAttached)
    { 
    <script src="../../Scripts/Mvc3/jquery-1.7-vsdoc.js" type="text/javascript"></script> @* intellisense! *@
     @Html.RelativeJavascript(Links.Scripts.Mvc3.jquery_1_7_js)
     @Html.RelativeJavascript(Links.Scripts.Mvc3.jquery_unobtrusive_ajax_js)
    }
    else
    {
        @Html.RelativeJavascript(Links.Scripts.Mvc3.jquery_1_7_min_js) 
        @Html.RelativeJavascript(Links.Scripts.Mvc3.jquery_unobtrusive_ajax_min_js)  
    }

Recommendations:

  • Use T4MVC in ALL cases even if you are pure webforms. The elimination of magic strings for static content (.js,.css, images, specifying templates) is outstanding.
    • and if you have any part of your build process compiling views then you get compile-time safety on any of those links.
    • 如果您的构建过程中有任何部分编译视图,那么您可以在任何这些链接上获得编译时安全性。

  • 即使您是纯webforms,也可以在所有情况下使用T4MVC。消除静态内容(.js,.css,图像,指定模板)的魔术字符串非常出色。如果您的构建过程中有任何部分编译视图,那么您可以在任何这些链接上获得编译时安全性。

#1


10  

Mvc is build on top of asp.net as is webforms, so yes it's easy. Done it couple of times for conversion purposes

Mvc建立在asp.net之上,就像webforms一样,所以是的,它很容易。做了几次转换的目的

Maybe this url's could help you:

也许这个网址可以帮到你:

http://www.hanselman.com/blog/IntegratingASPNETMVC3IntoExistingUpgradedASPNET4WebFormsApplications.aspx

and

http://www.hanselman.com/blog/PlugInHybridsASPNETWebFormsAndASPMVCAndASPNETDynamicDataSideBySide.aspx

#2


3  

One gotcha is don't put your WebForms inside the Views folder. I haven't get figured how to make MVC leave those paths alone. None of the ignore routing instructions seems to work in this case and the WebForms throw 404s.

一个问题是不要将您的WebForms放在Views文件夹中。我还没想到如何让MVC独自离开这些路径。在这种情况下,忽略路由指令似乎都不起作用,WebForms抛出404。

Other than that WebForms works perfectly fine alongside MVC since MVC2.

除了MVC2以外,WebForms与MVC一起工作得非常好。

#3


2  

Has anyone successfully deployed ASP.NET MVC alongside Web Forms in the same application in a production environment?

有没有人在生产环境中的同一个应用程序中成功部署ASP.NET MVC和Web Forms?

I never mixed ASP.NET MVC and classic WebForms in the same application. I make them run in separate applications and communicate between them with standard HTTP techniques (query string parameters, form posts, cookies, ...).

我从未在同一个应用程序中混合使用ASP.NET MVC和经典WebForms。我让它们在单独的应用程序中运行,并使用标准HTTP技术(查询字符串参数,表单帖子,cookie,...)在它们之间进行通信。

Is it really as easy as shown here in practice?

这真的和实践中显示的一样简单吗?

Yes, it is as easy as that.

是的,就这么简单。

#4


2  

Check out scott hanselmans AddMvc3ToWebForms nuget package. I am using it and its working pretty great. I am using it to gradually convert my web forms app to mvc

查看scott hanselmans的AddMvc3ToWebForms nuget包。我正在使用它,它的工作非常好。我正在使用它逐步将我的Web表单应用程序转换为mvc

#5


2  

I've spent a lot of time over the past few months on this. Here are my observations.

过去几个月我花了很多时间在这上面。以下是我的观察。

The good/easy - Getting Webforms to call into MVC controllers - It was remarkably easy to stand up a new MVC3 project and drop Webforms pages into it. - I was able to move my <pages><controls></controls></pages> section into the /pages directory in a new web.config there

好/易 - 让Webforms调用MVC控制器 - 站起来一个新的MVC3项目并将Webforms页面放入其中非常容易。 - 我能够将 部分移动到新的web.config中的/ pages目录中

The dirty/difficult

  • Regarding the GUID

    关于GUID

    • Please note that the GUID has to be added at the front of the line for some reason... everytime I tried it failed. Until I stumbled on a post that insisted it be the before the others.
    • 请注意,由于某种原因,必须在行的前面添加GUID ...每次我尝试失败时。直到我偶然发现一个坚持它在其他人之前的帖子。

    • also I don't know what the difference is but I have a different GUID working... {E53F8FEA-EAE0-44A6-8774-FFD645390401}
    • 我也不知道有什么不同但我有一个不同的GUID工作... {E53F8FEA-EAE0-44A6-8774-FFD645390401}

  • getting the landing page to be Webforms caused ALL kinds of snags.

    使着陆页成为Webforms会导致各种障碍。

  • getting jQuery intellisense to play nicely with T4MVC
  • 让jQuery intellisense与T4MVC很好地配合

this is what I did to address that

这就是我为解决这个问题所做的工作

@if (System.Diagnostics.Debugger.IsAttached)
    { 
    <script src="../../Scripts/Mvc3/jquery-1.7-vsdoc.js" type="text/javascript"></script> @* intellisense! *@
     @Html.RelativeJavascript(Links.Scripts.Mvc3.jquery_1_7_js)
     @Html.RelativeJavascript(Links.Scripts.Mvc3.jquery_unobtrusive_ajax_js)
    }
    else
    {
        @Html.RelativeJavascript(Links.Scripts.Mvc3.jquery_1_7_min_js) 
        @Html.RelativeJavascript(Links.Scripts.Mvc3.jquery_unobtrusive_ajax_min_js)  
    }

Recommendations:

  • Use T4MVC in ALL cases even if you are pure webforms. The elimination of magic strings for static content (.js,.css, images, specifying templates) is outstanding.
    • and if you have any part of your build process compiling views then you get compile-time safety on any of those links.
    • 如果您的构建过程中有任何部分编译视图,那么您可以在任何这些链接上获得编译时安全性。

  • 即使您是纯webforms,也可以在所有情况下使用T4MVC。消除静态内容(.js,.css,图像,指定模板)的魔术字符串非常出色。如果您的构建过程中有任何部分编译视图,那么您可以在任何这些链接上获得编译时安全性。