失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > 部署asp.net mvc_在ASP.NET 2.0上部署ASP.NET MVC

部署asp.net mvc_在ASP.NET 2.0上部署ASP.NET MVC

时间:2021-02-22 15:57:40

相关推荐

部署asp.net mvc_在ASP.NET 2.0上部署ASP.NET MVC

部署 mvc

This post will be filled with disclaimers and warnings. They are not just to CYA, but also toCmyAand 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 MVC running under 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进行合作,以尝试找出一种使 MVC在 2.0 SP1下运行的方法。 肖恩有这个主意,并告诉罗布“去解决这个问题”。 Rob真的很忙于做MVC店面,所以他告诉我“去弄清楚,你喜欢这种怪异的东西”。

Take a moment to look at my post on How to set an IIS Application or AppPool to use 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以使用 3.5而不是2.0”,以了解.NET 2.0和.NET 3.5之间的物理关系。 即使CLR大致相同,也有很多事情在2.0和3.5之间进行。

I was brainstorming ways to get MVC running on a .NET 2.0 machine and there were a couple of ways. I could recompile/fork all the stuff at /aspnet and compile via #ifdefs or manually an 2.0 version. However, then I'd have to maintain multiple versions, it could get really messy really quick.

我正在集思广益,使 MVC在.NET 2.0机器上运行,但有两种方法。 我可以在/aspnet上重新编译/分叉所有内容,并通过#ifdefs或手动使用 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 MVC application working if I:

最后,我与Brad Abrams进行了交谈,并花了最后几周的时间,不停地与拥有该框架不同部分的所有不同小组进行交谈。 我表示,如果出现以下情况,我可以使Hello World MVC应用程序正常工作:

Developed on Visual Studio 在Visual Studio 上开发 Targeted .NET 2.0 in Project Properties 项目属性中的目标.NET 2.0Deployed the Application to a .NET 2.0 SP1 machine 将应用程序部署到.NET 2.0 SP1计算机

Copied System.Core.dlllocalto 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 MVC on a machine that you just can't put .NET 3.5 on yet.

从技术上讲,这是我们不允许执行的最后一步,但是我向您展示了如何在实际情况下做到这一点;您想在无法安装.NET 3.5的计算机上使用 MVC然而。

以下是免责声明:(Here's the disclaimers:)

This workaround is offered with exactly zero warranty or support. It's as-is, just an FYI on the blog. If this hack deletes files or kills your cat, you have been warned. No whining. 此解决方法提供的保修或支持完全为零。 一切照旧,只是博客上的仅供参考。 如果此黑客删除了文件或杀死了猫,则已被警告。 不要抱怨 In practice, no one really knows what might break. Microsoft didn't test this. 在实践中,没有人真正知道会发生什么。 微软没有对此进行测试。 You must not redistribute System.Core.dll to a 3rd party. You mustn't bundle it or ship it with your application. 您不得将System.Core.dll重新分发给第三方。 您不能捆绑它或将其与您的应用程序一起交付。

When you update to .NET 3.5,remove your local copyof System.Core.dll

当您更新到.NET 3.5时,请删除System.Core.dll的本地副本

Don't GAC System.Core.dll. 不要GAC System.Core.dll。

Don't taunt System.Core.dll.

不要嘲笑System.Core.dll 。

Take a moment and read #3 again. 花一点时间,再次阅读#3。 This just flat might not work for you. Sorry. 这只公寓可能对您不起作用。 抱歉。 Don't do this to any machine that you don't own. 不要对您不拥有的任何计算机执行此操作。 I wanted to have an even ten, so this is a placeholder disclaimer in case I forgot one. 我希望有10个,所以如果我忘了一个,这是一个占位符免责声明。

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 MVC Web Application, you'll need to set your Project Target Framework to 2.0 in Project Properties:

在 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 将尝试阻止您 (VS 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 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 VS, 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应用程序。 一些较酷的 MVC东西将无法正常工作,尤其是在Views中,如果您尝试将Lambda与HtmlHelpers一起使用或使用var关键字。 这是因为自从您使用VS以来,开发计算机的编译器为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。

部署到计算机 (Deploying to an 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 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上部署 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 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.

将我的 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 VS 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开发计算机(这是您正在开发的运行VS的计算机)中的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 onyour deployment machineand 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 YouAppearto Get With This Hack)

MVC seems to work 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 MVC is a good thing, and maybe get him/her to let you upgrade the server to 3.5 with the promise of even cooler stuff. 向老板显示 MVC是一件好事,并且可以让他/她让您将服务器升级到 3.5,并且拥有更酷的承诺。

I was able to get a full Northwind Sample Site up using 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的 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.0SP1(x86 or x64)

.NET Framework 2.0SP1( x86或x64 )

/mvc and /mvc

/mvc和/mvc

Other Unsupported 3.5 on 2.0 Hacks

其他不受支持的3.5 on 2.0黑客

/fmarguerie/archive//09/05/linq-support-on-net-2-0.aspx

/fmarguerie/archive//09/05/linq-support-on-net-2-0.aspx

/nutshell/linqbridge.html

/nutshell/linqbridge.html

/blogs/main/archive//09/05/linq-support-on-net-2.0.aspx

/blogs/main/archive//09/05/linq-support-on-net-2.0.aspx

/how-to-use-net-35-syntax-and-compiler-features-for-net-20/

/how-to-use-net-35-syntax-and-compiler-features-for-net-20/

翻译自: /blog/deploying-aspnet-mvc-on-aspnet-20

部署 mvc

如果觉得《部署asp.net mvc_在ASP.NET 2.0上部署ASP.NET MVC》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。