c# - 未在 Azure 包中创建 Web.config

标签 c# asp.net-mvc-4 azure assembly-binding-redirect

我正在尝试使用 SDK 工具版本 2.2 在 Azure 中运行现有的工作 Web 应用程序。该 Web 应用程序可以作为“正常”MVC 4 站点正常运行,并且在本地 Azure 模拟器中也可以正常运行。该应用程序设计为安装在服务器上或作为 Web 角色运行。

我整个周末都在尝试将其发布到 Azure,但始终无法得到

Server Error in '/' Application

消息。通过启用远程桌面,我可以查看事件日志,这就是我收到的消息。

(紧随其后,但出于 tl;dr 的目的,我认为绑定(bind)重定向没有被拾取,因为主要的提示是 System.Web.Mvc 3.0.0.0 无法加载。)

Event code: 3005 
Event message: An unhandled exception has occurred. 
Event time: 11/3/2013 10:36:10 AM 
Event time (UTC): 11/3/2013 10:36:10 AM 
Event ID: 2be088053f02484e95f3f17fcd95b67e 
Event sequence: 1 
Event occurrence: 1 
Event detail code: 0 

Application information: 
Application domain: /LM/W3SVC/1273337584/ROOT-1-130279485699443947 
Trust level: Full 
Application Virtual Path: / 
Application Path: F:\sitesroot\0\ 
Machine name: RD00155D463D30 

Process information: 
Process ID: 1536 
Process name: w3wp.exe 
Account name: NT AUTHORITY\NETWORK SERVICE 

Exception information: 
Exception type: InvalidOperationException 
Exception message: The pre-application start initialization method Initialize on type    Elmah.Mvc.Bootstrap threw an exception with the following error message: Could not load file or assembly 'System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040).
at System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection`1 methods, Func`1 setHostingEnvironmentCultures)
at System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods)
at System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath)
at System.Web.Compilation.BuildManager.ExecutePreAppStart()
at System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException)

Could not load file or assembly 'System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
at Elmah.Mvc.Bootstrap.Initialize()

Request information: 
Request URL: http://blizzard-propressroom.cloudapp.net/ 
Request path: / 
User host address: 176.27.246.0 
User:  
Is authenticated: False 
Authentication Type:  
Thread account name: NT AUTHORITY\NETWORK SERVICE 

Thread information: 
Thread ID: 5 
Thread account name: NT AUTHORITY\NETWORK SERVICE 
Is impersonating: False 
Stack trace:    at System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection`1 methods, Func`1 setHostingEnvironmentCultures)
at System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods)
at System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath)
at System.Web.Compilation.BuildManager.ExecutePreAppStart()
at System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException)

我尝试卸载 ELMAH,以防万一,但我仍然无法加载 MVC 版本 3.0.0.0。

现在这当然是有道理的,因为我正在运行 MVC 4,这就是我的包中的内容。

当然,在本地运行 v4 不是问题,因为我的 Web.config 有:

<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>

但显然 Azure WebRoles 无法使用 Web.config(果然,如果我通过远程桌面找到源,那里几乎是空的 Web.config 文件)。

我看到有人建议我需要一个 app.config,我已经尝试过(只是 web.config 的直接副本)并将“复制”设置为“始终复制”。我可以看到我的 bin 文件夹中有一个副本。

这一切对我来说似乎是一个非常令人困惑的循环,但 Azure 上绑定(bind)重定向的规则似乎随着每个 SDK 版本的不同而变化,因此网上存在大量相互冲突的信息。

因此,在一篇非常长的文章之后:请问有人知道我需要做什么才能告诉 Azure 有关绑定(bind)重定向的信息吗?(您是否同意这实际上是问题所在?)

更新

感谢@viperguynaz 提供的一些建议,但要确认我的 System.Web.MVC 已标记为复制正确。今天早上,我尝试完全删除我的 Azure 项目,并使用 Visual Studio 中的“转换为 Windows Azure 云服务项目”选项,以防最初出现任何问题。但我仍然遇到同样的问题。

使用 Azure 服务上的远程桌面,我已转到 E:\sitesroot\0。那里的 Web.config 实际上是空的。只是:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.web>
        <machineKey decryption="AES" decryptionKey="F7FA540B4DFD82E5BB196B95D15FF81F6FC418E967F01A1C60FB407A84615031" validation="SHA1" validationKey="6FC418E967F01A1C60FB407A84615031902C0D9A9DE62168764FF0DCE537184F0535D5D9AD66DEDC6FC418E967F01A1C60FB407A84615031902C0D9A97DC1ABF" />
    </system.web>
</configuration>

没有我的 web.config 的迹象。但其他一切都存在且正确,包括 Views 文件夹中的 Web.config。

我最新的构建和发布告诉我在构建过程中一些非常有趣的事情:

warning WAT153: The web project 'xxx' is dependent on the following MVC assembly: C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 3\Assemblies\System.Web.Mvc.dll.
warning WAT153: The web project 'xxx' is dependent on the following MVC assembly: C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\Assemblies\System.Web.WebPages.dll.
warning WAT153: The web project 'xxx' is dependent on the following MVC assembly: C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\Assemblies\System.Web.Razor.dll
warning WAT153: The web project 'xxx' is dependent on the following MVC assembly: C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\Assemblies\System.Web.WebPages.Razor.dll.
warning WAT153: The web project 'xxx' is dependent on the following MVC assembly: C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\Assemblies\System.Web.WebPages.Deployment.dll.

对于所有这些:

MVC assemblies must be added to the package or installed on the virtual machine for your web role. For more details about this, see the following help page: http://go.microsoft.com/fwlink/?LinkId=218227.

现在这似乎很清楚,除了它们都设置为随项目复制,并且我的项目设置为 Web 角色(如链接所示)。链接中有关于必须使用 ASP Net MVC 安装创建启动文件夹并添加 WebStart cs 的讨论,但我觉得这是过时的建议,否则为什么不“转换为 Windows Azure 云服务项目” “做这些工作吗?

更新2

好的,看起来我的 Web.config 文件由于某种原因没有被打包。我翻出了一个已经在Azure中成功安装的项目,打开7-zip中的包文件,发现里面捆绑了一个Web.config文件。此问题项目中没有这样的 web.config 文件。我将开始尝试找出原因。

我还更新了问题标题以反射(reflect)此信息。几乎可以肯定,这就是一切的原因。

最佳答案

事实证明,这与Azure ASP.NET MVC Web.Config Deployment Issue的情况相同。

我的 web.config 的部署值为“none”(不知何故),因此没有包含在包中,这意味着创建了一个几乎空的默认值。

我将部署类型更改为“内容”(使用 Web.config 上的属性),现在正在捆绑它。

关于c# - 未在 Azure 包中创建 Web.config,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19754207/

相关文章:

c# - C# 中的惰性字典属性

c# - 在Windows Phone上同时播放声音

c# - MVC 4 外键不工作

azure - 如何获取 ADF 中自纪元以来的毫秒数

azure - 是否可以使用 MSAL 获取 Azure AD V1 token ?

java - 有没有办法使用 Java 从 Azure AD 恢复最近删除的用户?

c# - Selenium C# - 加载配置文件在 Firefox 48 中抛出异常

c# - String.IsNullOrEmpty 或 string.IsNullOrEmpty

c# - IEnumerable 模型中的多个 DropDownList

c# - MVC4 bundle 返回 404