gpt4 book ai didi

asp.net - 组件化的 ASP.NET MVC 应用程序是否可以顺利部署?

转载 作者:行者123 更新时间:2023-12-04 00:36:47 26 4
gpt4 key购买 nike

这可能不是 MVC 特定的,它也可能适用于 ASP.NET WebForms,但到目前为止我们已经在 MVC2 上体验过它。

每当我们使用 MSDeploy 开始远程部署时,我们都会收到一个简短的(5-6 秒)“服务器错误”页面,用于我们的请求,直到进行新的部署。这是错误文本:

Server Error in '/' Application.

Could not load file or assembly 'Some.Assembly' or one of its dependencies. The process cannot access the file because it is being used by another process. (Exception from HRESULT: 0x80070020)

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.FileLoadException: Could not load file or assembly 'Some.Assembly' or one of its dependencies. The process cannot access the file because it is being used by another process. (Exception from HRESULT: 0x80070020)

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1



以下是错误页面中显示的堆栈跟踪:
[FileLoadException: Could not load file or assembly 'Some.Assembly' or one of its dependencies. The process cannot access the file because it is being used by another process. (Exception from HRESULT: 0x80070020)]
System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +39
System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks) +132
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +144
System.Reflection.Assembly.Load(String assemblyString) +28
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +46

[ConfigurationErrorsException: Could not load file or assembly 'Some.Assembly' or one of its dependencies. The process cannot access the file because it is being used by another process. (Exception from HRESULT: 0x80070020)]
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +618
System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +209
System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +130
System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +178
System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +94
System.Web.Compilation.BuildManager.CallPreStartInitMethods() +332
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +591

[HttpException (0x80004005): Could not load file or assembly 'Some.Assembly' or one of its dependencies. The process cannot access the file because it is being used by another process. (Exception from HRESULT: 0x80070020)]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +8950644
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +97
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +256

导致该故障的程序集(Some.Assembly)不是实际的 Web 程序集,而是它的“引用”下的其他组件之一,用 .snk 签名。

5-6 秒后,站点启动,错误消失。

这当然不是想要的行为。我想知道我们是否在将组件连接在一起方面做错了什么。是否应该有另一种方法来确保顺利部署?或者这可能是 MVC2 本身的错误?

附言IIS 重叠旋转已启用,无论如何它都是默认设置。

以下是组件:
  • A.dll
  • Some.Assembly.dll (<--- 这是失败的,取决于 A.dll)
  • B.dll(取决于 A.dll 和 Some.Assembly.dll)
  • Web.dll(这是 Web 应用程序,取决于以上所有内容)

  • 所有依赖项都是使用带有 Copy Local 的常规程序集引用建立的。启用。所有 dll 都是作为单独项目的解决方案的一部分。

    MSDeploy 只部署二进制文件,而不是源文件。

    最佳答案

    重叠旋转仅适用于池回收,并不旨在促进您描述或要求的部署类型。当启用重叠轮换时,池的“传出”工作进程中的现有请求将被允许完成,而新请求将被发送到创建的新工作进程。这是一种优雅地切换到新工作进程的机制,而无需从现有请求下面拉扯地毯。这就是它所做的一切。

    卷影复制文件夹 用于此目的:

    What is the “Temporary ASP.NET Files” folder for? (My Answer)



    同样,它们不打算提供一种机制来促进在您上传新站点时保持整个现有代码库运行。

    当您部署 ASP.NET 应用程序时,该站点将出现异常行为。当您复制程序集时,这些文件将被处理上传的任何进程(WebDAV 或 FTP)锁定(可能是唯一的)。

    这会导致您观察到的异常,并且很可能是因为卷影复制机制在写入新程序集之前无法读取它们(并且 WebDAV 或 FTP 删除了写入锁定)。

    此外,如果预期的方法签名已更改或被删除,则任何依赖于这些程序集的页面都可能无法(影子)编译,直到正确的页面被上传。或者,如果页面/ View 首先上传取决于尚未部署的程序集中的功能,您也会收到错误。

    在部署最后一个文件之前,整个站点将处于不一致状态。

    IIS 中没有内置机制来确保“原子”部署,即加载所有内容然后切换到运行它。 IIS 将继续为站点提供请求,而 ASP.NET 仍将在您上传应用程序时继续检测文件更改。

    在不产生这些错误的情况下部署应用程序的唯一方法是启用一个名为 App_Offline.htm 的特殊页面。在部署之前,然​​后在部署之后重命名或删除:

    App_Offline.htm - Scott Guthrie
    App_Offline.htm and working around the "IE Friendly Errors" feature



    您可能还会发现这篇文章很有用:

    How to: Prepare to Deploy a Web Project



    还有一个稍微复杂的替代方案,它涉及两个文件夹,例如:
    d:\websites\site\www-A d:\websites\site\www-B
    运行站点指向 d:\websites\site\www-A ,同时你部署到 d:\websites\site\www-B .准备好后,将站点切换到 d:\websites\site\www-B文件夹。

    当您部署下一个构建时,您将部署到 d:\websites\site\www-A当你快乐时切换到那个。

    缺点是您需要注意并记住哪个文件夹是哪个。

    此外,任何用户上传的内容都需要在两个文件夹之间同步(尽管您可以将第三个文件夹映射到类似的虚拟目录)。

    关于asp.net - 组件化的 ASP.NET MVC 应用程序是否可以顺利部署?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4521208/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com