ASP.NET MVC alongside Web Forms in the same web app?

后端 未结 5 1924
深忆病人
深忆病人 2020-12-03 09:02

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 doi

5条回答
  •  春和景丽
    2020-12-03 09:37

    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 section into the /pages directory in a new web.config there

    The dirty/difficult

    • Regarding the 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.
      • also I don't know what the difference is but I have a different GUID working... {E53F8FEA-EAE0-44A6-8774-FFD645390401}
    • getting the landing page to be Webforms caused ALL kinds of snags.

    • getting jQuery intellisense to play nicely with T4MVC

    this is what I did to address that

    @if (System.Diagnostics.Debugger.IsAttached)
        { 
         @* 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.

提交回复
热议问题