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

我一直在尝试将整个周末发布到Azure,但始终

Server Error in '/' Application


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

(此之后,但是出于tl; dr的目的,我认为未选择绑定重定向,因为主要的抱怨是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文件夹中有一个副本。

这一切似乎让我感到迷惑不解,但似乎每个SDK版本都对Azure绑定绑定重定向的规则有所更改,因此在线上存在大量冲突信息。

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

更新资料

感谢@viperguynaz提供了一些建议,但是要确认我的System.Web.MVC被标记为true。今天早上,我尝试完全删除我的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.


现在看起来很清楚,除了它们都将设置为与项目一起复制,并且我的项目被设置为网络角色(如链接所示)。链接中有这样的话题:必须通过ASP Net MVC安装创建启动文件夹,并添加WebStart cs,但我觉得这是过时的建议,否则为什么不“转换为Windows Azure Cloud Service Project这些工作吗?

更新2

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

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

最佳答案

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

我的web.config的部署值为“ none”(以某种方式),因此未包含在软件包中,这意味着创建了几乎为空的默认值。

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

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

10-10 17:24
查看更多