部署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:)

  1. 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. 此解决方法提供的保修或支持完全为零。 一切照旧,只是博客上的仅供参考。 如果此黑客删除了文件或杀死了猫,则已被警告。 不要抱怨
  2. In practice, no one really knows what might break.  Microsoft didn't test this. 在实践中,没有人真正知道会发生什么。 微软没有对此进行测试。
  3. 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重新分发给第三方。 您不能捆绑它或将其与您的应用程序一起交付。
  4. When you update to .NET 3.5, remove your local copy of System.Core.dll

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

  5. Don't GAC System.Core.dll. 不要GAC System.Core.dll。
  6. Don't taunt System.Core.dll.

    不要嘲笑System.Core.dll 。

  7. Take a moment and read #3 again. 花一点时间,再次阅读#3。
  8. This just flat might not work for you. Sorry. 这只公寓可能对您不起作用。 抱歉。
  9. Don't do this to any machine that you don't own. 不要对您不拥有的任何计算机执行此操作。
  10. 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 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相关推荐

  1. iis 6.0上部署.net 2.0和4.0网站

    网站环境 IIS6.0,操作系统Windows server2003 sp2,服务器之前已经部署了.net 2.0和asp的网站,现在要部署新开发的.net 4.0网站. 大体部署流程如下: 1.官网 ...

  2. win2003 sp2+iis 6.0上部署.net 2.0和.net 4.0网站的方法

    网站环境 IIS6.0,操作系统Windows server2003 sp2,服务器之前已经部署了.net 2.0和asp的网站,现在要部署新开发的.net 4.0网站.本来认为很简单,却遇到了很多问 ...

  3. 机器学习 部署 嵌入式_如何在移动和嵌入式设备上部署机器学习模型

    机器学习 部署 嵌入式 介绍 (Introduction) Thanks to libraries such as Pandas, scikit-learn, and Matplotlib, it i ...

  4. 如何在服务器上部署pdf文件,详解如何在云服务器上部署Laravel.pdf

    详详解解如如何何在在云云服服务务器器上上部部署署Laravel 学习PHP和Laravel 已经有一段时间了,但是所有的代码都是跑在 地的虚拟主机上的,于是去腾讯云申请了一个月的免费云主机 ,想把项目 ...

  5. 在Apache上调试Asp.net 1.1/2.0代码

    我们知道ASP.NET 1.1的项目由于微软设计和实现的原因,对IIS的依赖非常的紧密.不管是创建ASP.NET项目,还是打开.调试ASP.NET项目,都要求IIS运行正常,否则什么都做不成.那么当我 ...

  6. 在安卓上部署服务器 - 解决内网穿透

    原文地址:在安卓上部署服务器 - 解决内网穿透 本系列其他文章: 在安卓上部署服务器 在安卓上部署服务器 – 应用程序的配置 在安卓上部署服务器 – 解决内网穿透问题 在安卓上部署服务器 – 部署脚本 ...

  7. 在 Android 上部署Machine Learning(ML) 模型

    @如何在 Android 上部署机器学习 (ML) 模型 ** 如何在 Android 上部署Machine Learning(ML) 模型 ** 目录 Android上的 ML 项目工作流程 在 A ...

  8. 在CentOS上部署基于dnx/coreclr的ASP.NET 5应用程序

    在Ubuntu上写好了一个简单的ASP.NET 5应用程序,尝试将这个程序部署在没有mono环境的CentOS服务器上. 部署步骤如下: 1)安装libuv(KestrelHttpServer需要它) ...

  9. ASP.NET在IIS上部署使用Oracle数据库无法连接数据库解决方法

    ASP.NET在IIS上部署使用Oracle数据库无法连接数据库解决方法(转载) 10小时前 ASP.NET在IIS上部署使用Oracle数据库无法连接数据库解决方法(转载) 分类: ASP.NET| ...

  10. 一起谈.NET技术,在Mono 2.8上部署ASP.NET MVC 2

    我们知道Mono 2.8对ASP.NET MVC 2的完全支持,下面我们就来测试下在Mono 2.8上部署ASP.NET MVC 2应用程序.我的环境是Opensuse 11.3,通过以下命令部署好M ...

最新文章

  1. ganglia安装与配置
  2. ida so 不root_十字符病毒,杀不死的小强,一次云服务器沦陷实录
  3. linux 查看端口被哪个程序占用
  4. 条件语句:case语句
  5. Windows下编译和安装Boost库
  6. python文件合并_用Python 将两个文件的内容合并成一个新的文件.
  7. 13 MM配置-主数据-定义物料状态
  8. 运营商取消不限量套餐 网友:这是变相涨价
  9. IDEA中Git合并冲突
  10. 2016/03/30
  11. Windows下SVN已检出项目自动更新
  12. 通过图标来识别网站用户指纹
  13. excel函数:VLOOKUP+IF多条件匹配取值(数组函数)
  14. 只有努力了,你才能成为想要的样子
  15. 从懵懵懂懂到如今的恍恍惚惚
  16. Linux CentOS服务器时间同步阿里云北京时间
  17. 前端对接钉钉的步骤以及代码
  18. 抱歉,我又可以了。。。
  19. android水波进度条,Android--水波纹进度条
  20. 5G室内小型基站行业现状调研及趋势分析报告

热门文章

  1. xp任务栏一直闪跳怎么办_电脑任务栏闪烁以及任务栏图标闪烁解决办法
  2. msgbox.html5.qq.com,怎样制作qq透明背景皮肤
  3. 数字转人民币大写,PHP实现
  4. Java实现图片压缩功能
  5. 电商erp软件有哪些好处?
  6. Erlang学习时间曲线
  7. 使用Flash骨骼工具制作角色动画
  8. 项目管理面试常见问题及答案
  9. 较为安全快捷的更改C盘用户文件夹名称的方式!(2022.8.22)windows10和11均可用
  10. wex5 checkbox