部署asp.net mvc_在ASP.NET 2.0上部署ASP.NET MVC
部署asp.net mvc
This post will be filled with disclaimers and warnings. They are not just to CYA, but also to C my A and avoid my getting sacked.
這篇文章將充滿免責聲明和警告。 他們不僅是為了CYA ,而且是為了C我的A,并避免我被解雇。
I've been working with Shawn Burke and Rob Conery and the magical Eilon Lipton to try to figure out a way to get ASP.NET MVC running under ASP.NET 2.0 SP1. Shawn had this idea and told Rob "go figure this out." Rob was really busy doing the MVC Storefront so he told me "go figure this out, you like this kind of freaky stuff."
我一直在與Shawn Burke和Rob Conery以及神奇的Eilon Lipton進行合作,以嘗試找出一種使ASP.NET MVC在ASP.NET 2.0 SP1下運行的方法。 肖恩有這個主意,并告訴羅布“去解決這個問題”。 Rob真的很忙于做MVC店面,所以他告訴我“去弄清楚,你喜歡這種怪異的東西”。
Take a moment to look at my post on How to set an IIS Application or AppPool to use ASP.NET 3.5 rather than 2.0 for background on the physical relationship between .NET 2.0 and .NET 3.5.? There's a lot of stuff going on between 2.0 and 3.5, even though the CLR is more or less the same.
花點時間看一下我的文章“如何設置IIS應用程序或AppPool以使用ASP.NET 3.5而不是2.0”,以了解.NET 2.0和.NET 3.5之間的物理關系。 即使CLR大致相同,也有很多事情在2.0和3.5之間進行。
I was brainstorming ways to get ASP.NET MVC running on a .NET 2.0 machine and there were a couple of ways. I could recompile/fork all the stuff at http://www.codeplex.net/aspnet and compile via #ifdefs or manually an ASP.NET 2.0? version. However, then I'd have to maintain multiple versions, it could get really messy really quick.
我正在集思廣益,使ASP.NET MVC在.NET 2.0機器上運行,但有兩種方法。 我可以在http://www.codeplex.net/aspnet上重新編譯/分叉所有內容,并通過#ifdefs或手動使用ASP.NET 2.0版本進行編譯。 但是,那時我必須維護多個版本,它很快就會變得非常混亂。
I ended up speaking to Brad Abrams and spent the last few weeks, on and off, talking to all the different groups that owned different parts of the framework. I expressed that I could get a Hello World ASP.NET MVC application working if I:
最后,我與Brad Abrams進行了交談,并花了最后幾周的時間,不停地與擁有該框架不同部分的所有不同小組進行交談。 我表示,如果出現以下情況,我可以使Hello World ASP.NET MVC應用程序正常工作:
- Developed on Visual Studio 2008 在Visual Studio 2008上開發
- Targeted .NET 2.0 in Project Properties 項目屬性中的目標.NET 2.0
- Deployed the Application to a .NET 2.0 SP1 machine 將應用程序部署到.NET 2.0 SP1計算機
Copied System.Core.dll local to the web apps /bin folder
Web應用程序/ bin文件夾本地復制的System.Core.dll
It's that final step that we're not technically allowed to do, but I'm showing you how to do it in case you real;y want to ASP.NET MVC on a machine that you just can't put .NET 3.5 on yet.
從技術上講,這是我們不允許執行的最后一步,但是我向您展示了如何在實際情況下做到這一點;您想在無法安裝.NET 3.5的計算機上使用ASP.NET MVC然而。
以下是免責聲明: (Here's the disclaimers:)
When you update to .NET 3.5, remove your local copy of System.Core.dll
當您更新到.NET 3.5時,請刪除System.Core.dll的本地副本
Don't taunt System.Core.dll.
不要嘲笑System.Core.dll 。
After all those sunny disclaimers, I do hope that this helps someone in some small way to get a development site running on .NET 2.0 while you prepare for an upgrade to .NET 3.5.
在獲得所有這些陽光燦爛的免責聲明之后,我確實希望這能以某種小方式幫助某人在準備升級到.NET 3.5時使開發站點在.NET 2.0上運行。
該怎么辦 (What To Do)
From an ASP.NET MVC Web Application, you'll need to set your Project Target Framework to 2.0 in Project Properties:
在ASP.NET MVC Web應用程序中,需要在“項目屬性”中將“項目目標框架”設置為2.0:
NOTE: This doesn't enable all of 3.5, or even much of .NET 3.5. But it does enable System.Web.Mvc and it's supporting assemblies to run as they are the ones with the reference to System.Core. However, remember, at this point, you and your project are living in .NET 2.0 world.
注意:這不會啟用全部3.5,甚至大部分.NET 3.5。 但是它確實啟用了System.Web.Mvc并支持程序集運行,因為它們是對System.Core的引用。 但是,請記住,此時,您和您的項目都位于.NET 2.0世界中。
Running 2.0 means you don't have LINQ to SQL or Entity Framework or anything. You'll need to use something else. In my example code I'm using Davy Brion's NHibernate Northwind Sample as it's a .NET 2.0 compiled solution and it'll be acting as my Model.
運行2.0意味著您沒有LINQ to SQL或Entity Framework或其他任何東西。 您將需要使用其他東西。 在我的示例代碼中,我使用的是Davy Brion的NHibernate Northwind Sample,因為它是.NET 2.0編譯的解決方案,它將充當我的模型。
VS 2008將嘗試阻止您 (VS 2008 Will Try to Stop You)
When you add references to System.Web.Routing, System.Web.Abstractions and System.Web.MVC you'll get warnings like this one. Click Yes. This is VS trying (rightfully) to protect you from confusion and assembly errors as we'll see, and if you click "yes" you're saying you really know what you're doing. From this point on, we're on our own.
當您添加對System.Web.Routing,System.Web.Abstractions和System.Web.MVC的引用時,您將收到類似這樣的警告。 單擊是。 這是VS試圖(正確地)保護您免受混淆和組裝錯誤的影響,我們將看到,如果您單擊“是”,則表示您確實知道自己在做什么。 從這一點開始,我們就靠自己了。
After this, you can develop your now .NET 2.0 application as you like, using 2.0 technologies. Some of the cooler ASP.NET MVC stuff won't work, particularly in the Views if you try to use lambdas with HtmlHelpers or use the var keyword. This is because while your development machine's compiler is 3.5 since you're using VS2008, when you deploy your ASPX views to the server side, that machine has only .NET 2.0 SP1 and will compile those views with the 2.0 compilers.
之后,您可以使用2.0技術隨意開發自己的.NET 2.0應用程序。 一些較酷的ASP.NET MVC東西將無法正常工作,尤其是在Views中,如果您嘗試將Lambda與HtmlHelpers一起使用或使用var關鍵字。 這是因為自從您使用VS2008以來,開發計算機的編譯器為3.5,而將ASPX視圖部署到服務器端時,該計算機只有.NET 2.0 SP1,并且將使用2.0編譯器來編譯這些視圖。
For example, this line of code in a view that showed a list of products...
例如,視圖中的這一行代碼顯示了產品列表...
<% foreach (var product in ViewData.Model) { %>
<%foreach(ViewData.Model中的乘積){%>
...gave me this error.
...給我這個錯誤。
CS0246: The type or namespace name 'var' could not be found (are you missing a using directive or an assembly reference?)
CS0246:找不到類型或名稱空間名稱“ var”(您是否缺少using指令或程序集引用?)
If you see errors like this, you'll know you're using 3.5isms that's not understood by the 2.0 compiler in your Views.
如果看到這樣的錯誤,您將知道您正在使用View的2.0編譯器無法理解的3.5ism。
部署到ASP.NET計算機 (Deploying to an ASP.NET Machine)
Since I'll be deploying on a machine with .NET 2.0 SP1, I'll use an XP SP2 Virtual Machine running IIS6. You can find a fantastic troubleshooting blog post by Omar Al Zabir on Deploying ASP.NET MVC on IIS 6 here. Suffice it to say, my routes use the .mvc extension, and I've associated .mvc with aspnet_isapi in the IIS6 management console.
由于我將在具有.NET 2.0 SP1的計算機上進行部署,因此我將使用運行IIS6的XP SP2虛擬機。 您可以在此處找到Omar Al Zabir撰寫的精彩的故障排除博客文章,內容涉及在IIS 6上部署ASP.NET MVC 。 可以這么說,我的路由使用.mvc擴展名,并且我已經將.mvc與IIS6管理控制臺中的aspnet_isapi關聯了。
I've also updated my routes to include the .mvc extension so IIS6 can "see" the requests:
我還更新了路由以包括.mvc擴展名,以便IIS6可以“查看”請求:
routes.MapRoute("mvcroute", "{controller}.mvc/{action}/{id}"
??? , new { controller="products", action = "Index", id = "" }
??? , new { controller=@"[^\.]*"});
Routes.MapRoute(“ mvcroute”,“ {controller} .mvc / {action} / {id}” ,新的{controller =“ products”,action =“ Index”,id =“”} ,新的{controller = @“ [^ \。] *”}));
ASIDE: If you like, you can certainly enable pretty URLs using ISAPI_Rewrite and remapping requests to extensionless URLs to .mvc or you can configure IIS6 with a wildcard map. I prefer the former.
旁白:如果愿意,您當然可以使用ISAPI_Rewrite啟用漂亮的URL,并將對無擴展名的URL的請求重新映射到.mvc,或者可以使用通配符映射配置IIS6。 我更喜歡前者。
After I deploy my ASP.NET MVC application over to my .NET 2.0 SP1 machine, again, in this case running IIS6, I might see this YSOD indicating I don't have System.Core on that machine. This makes sense because this machine doesn't have .NET 3.5 installed.
將我的ASP.NET MVC應用程序部署到.NET 2.0 SP1計算機上之后,再次,在這種情況下運行IIS6,我可能會看到此YSOD,表明該計算機上沒有System.Core。 這是有道理的,因為此計算機未安裝.NET 3.5。
Here's the moment of truth, and the moment we step from supported to unsupported. You can copy System.Core from your .NET 3.5 development machine (this is the machine running VS2008 that you're developing on) to the /bin folder on your .NET 2.0 SP1 machine. It's gotta be running .NET Framework 2.0 SP1 or this won't work.
這是關鍵時刻,也是我們從受支持邁向不受支持的那一刻。 您可以將.NET 3.5開發計算機(這是您正在開發的運行VS2008的計算機)中的System.Core復制到.NET 2.0 SP1計算機上的/ bin文件夾中。 必須運行.NET Framework 2.0 SP1,否則將無法正常運行。
System.Core is probably somewhere around "C:\windows\assembly\GAC_MSIL\System.Core\3.5.0.0__b77a5c561934e089" on your machine, but you're a bad person for even asking.
System.Core可能在您機器上的“ C:\ windows \ assembly \ GAC_MSIL \ System.Core \ 3.5.0.0__b77a5c561934e089”附近,但您甚至都不敢問。
Copy that file into your bin folder on your deployment machine and you should be able to Refresh past this error page.
將該文件復制到部署計算機上的bin文件夾中,您應該可以刷新此錯誤頁面。
黑客無法獲得的東西 (Things You Don't Get With This Hack)
- Support from Me or Microsoft (in that order) 我或Microsoft的支持(按順序)
- Any .NET 3.5 feature like LINQ to SQL or LINQ to Entities 任何.NET 3.5功能,例如LINQ to SQL或LINQ to Entities
- Many of the HtmlHelpers and cool things that work with Lambdas won't work with inline script in Views because those pages will be compiled on the server using the 2.0 compiler. 許多與Lambdas一起使用的HtmlHelpers和很酷的功能在Views中不能與內聯腳本一起使用,因為這些頁面將使用2.0編譯器在服務器上進行編譯。
- Good karma 好業力
您可能會從此黑客獲得的東西(Things You Appear to Get With This Hack)
- ASP.NET MVC seems to work ASP.NET MVC似乎可以工作
- Anything you can do in ordinarily in .NET 2.0 works 您可以在.NET 2.0中正常執行的任何操作
- Bragging rights 吹牛的權利
- A spot on your immortal soul 你不朽靈魂上的斑點
- The ability to show your boss that ASP.NET MVC is a good thing, and maybe get him/her to let you upgrade the server to ASP.NET 3.5 with the promise of even cooler stuff. 向老板顯示ASP.NET MVC是一件好事,并且可以讓他/她讓您將服務器升級到ASP.NET 3.5,并且擁有更酷的承諾。
I was able to get a full Northwind Sample Site up using ASP.NET MVC Preview 3 with NHibernate against the Northwind Database in about two hours. This was my first NHibernate application of any size and I'm sure I did it wrong, but it works on my machine! Thanks again to Davy Brion's most excellent and thoughtful example, it was a great way for me to learn NHibernate (which has a bit of a learning curve).
我可以在大約兩個小時內使用帶有NHibernate的ASP.NET MVC Preview 3和Northwind數據庫建立完整的Northwind示例站點。 這是我的第一個任何大小的NHibernate應用程序,我敢肯定我做錯了,但是可以在我的機器上運行! 再次感謝戴維·布瑞恩(Davy Brion)最出色和周到的榜樣,這對我來說是學習NHibernate的好方法( NHibernate有一點學習曲線)。
瀏覽Microsoft Legal (Navigating Microsoft Legal)
One thing that I wanted to add was that this was my first time navigating Microsoft Legal. I was dreading it. However, the LCA (Legal and Corporate Affairs) guy that helped me through it was exceedingly cool. Rather than what I expected - here's reasons why you CAN'T do this - he was more like, "what can we do to make this happen." I don't know if it's representative of Microsoft Legal in general, our division, or just this nice guy, but either way, it was cool and he's my go-to guy the next time I try something crazy.
我想補充的一件事是,這是我第一次瀏覽Microsoft Legal。 我很害怕。 但是,幫助我解決問題的LCA(法律和公司事務)人員非???。 而不是我所期望的-這是您無法做到這一點的原因-他更像是“我們可以做些什么來實現這一目標?!?我不知道是一般的Microsoft Legal,我們的部門的代表,還是這個好人,但是無論哪種方式,這都很酷,下次我嘗試瘋狂的事情時,他是我的首選。
Related Links
相關鏈接
.NET Framework 2.0 SP1 (x86 or x64)
.NET Framework 2.0 SP1 ( x86或x64 )
http://www.asp.net/mvc and http://www.codeplex.com/mvc
http://www.asp.net/mvc和http://www.codeplex.com/mvc
Other Unsupported 3.5 on 2.0 Hacks
其他不受支持的3.5 on 2.0黑客
http://weblogs.asp.net/fmarguerie/archive/2007/09/05/linq-support-on-net-2-0.aspx
http://weblogs.asp.net/fmarguerie/archive/2007/09/05/linq-support-on-net-2-0.aspx
http://www.albahari.com/nutshell/linqbridge.html
http://www.albahari.com/nutshell/linqbridge.html
http://linqinaction.net/blogs/main/archive/2007/09/05/linq-support-on-net-2.0.aspx
http://linqinaction.net/blogs/main/archive/2007/09/05/linq-support-on-net-2.0.aspx
http://rabdullin.com/how-to-use-net-35-syntax-and-compiler-features-for-net-20/
http://rabdullin.com/how-to-use-net-35-syntax-and-compiler-features-for-net-20/
翻譯自: https://www.hanselman.com/blog/deploying-aspnet-mvc-on-aspnet-20
部署asp.net mvc
總結
以上是生活随笔為你收集整理的部署asp.net mvc_在ASP.NET 2.0上部署ASP.NET MVC的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JAVA高效批量插入数据到数据库demo
- 下一篇: 故障分析 | OceanBase Pro