【问题标题】:Do Virtual Directories in shared hosting conflict with stuff in wwwroot?共享主机中的虚拟目录是否与 wwwroot 中的内容冲突?
【发布时间】:2026-01-14 05:00:01
【问题描述】:

我有一个 asp.net mvc 应用程序、phpBB 论坛和 asp.net webservice,我希望它们都在同一个 wwwroot 中。

我的共享主机允许虚拟目录,所以我做了一个。它在其中创建了目录和一些 web.config。

然后我上传了我的 asp.net 网络服务,并用来自网络服务的那个覆盖了虚拟目录中的 web.config。

 Could not load file or assembly 'System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
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.FileNotFoundException: Could not load file or assembly 'System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Assembly Load Trace: The following information can be helpful to determine why the assembly 'System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' could not be loaded.

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].


Stack Trace:

[FileNotFoundException: Could not load file or assembly 'System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.]
   System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) +0
   System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) +43
   System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +127
   System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +142
   System.Reflection.Assembly.Load(String assemblyString) +28
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +46

[ConfigurationErrorsException: Could not load file or assembly 'System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.]
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +613
   System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +57
   System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +178
   System.Web.Compilation.WebDirectoryBatchCompiler..ctor(VirtualDirectory vdir) +163
   System.Web.Compilation.BuildManager.BatchCompileWebDirectoryInternal(VirtualDirectory vdir, Boolean ignoreErrors) +53
   System.Web.Compilation.BuildManager.BatchCompileWebDirectory(VirtualDirectory vdir, VirtualPath virtualDir, Boolean ignoreErrors) +175
   System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath) +83
   System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile) +261
   System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile) +101
   System.Web.Compilation.BuildManager.GetVPathBuildResult(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile) +83
   System.Web.Compilation.BuildManager.GetVPathBuildResult(HttpContext context, VirtualPath virtualPath) +10
   System.Web.UI.WebServiceParser.GetCompiledType(String inputFile, HttpContext context) +43
   System.Web.Services.Protocols.WebServiceHandlerFactory.GetHandler(HttpContext context, String verb, String url, String filePath) +180
   System.Web.Script.Services.ScriptHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated) +47
   System.Web.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +307
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

所以我不知道为什么它想要 MVC .dll 是不是因为我删除了虚拟目录中的默认 web.config 而生气?

好的,我有这个

    <location path="." inheritInChildApplications="false">
        <compilation debug="true">
            <assemblies>
                <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
                <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
                <add assembly="System.Web.Abstractions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
                <add assembly="System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
                <add assembly="System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
                <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
                <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
                <add assembly="System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
                <add assembly="System.Data.Entity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
            </assemblies>
        </compilation>
    </location>

但我明白了

Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: <location> sections are allowed only within <configuration> sections.

Source Error:

Line 68:             during development.
Line 69:     -->
Line 70:        <location path="." inheritInChildApplications="false">
Line 71:            <compilation debug="true">
Line 72:                <assemblies>

我也试过了

<configuration>
  <location path="."  inheritInChildApplications="false">
    <configSections>

所以它首先需要 configSections 但我不确定将它移到哪里

 Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: Only one <configSections> element allowed per config file and if present must be the first child of the root <configuration> element.

Source Error:

Line 10: <configuration>
Line 11:   <location path="."  inheritInChildApplications="false">
Line 12:    <configSections>
Line 13:        <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
Line 14:            <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=n

【问题讨论】:

    标签: asp.net-mvc web-services hosting virtual-directory


    【解决方案1】:

    您是否将 MVC dll 放入您的 /bin 文件夹中?

    有时它会在本地工作,因为 MVC 箱在 GAC 中,但它们可能不在服务器上的 GAC 中。

    预计到达时间:

    听起来您的虚拟网络服务可能正在从主网络继承设置。您的主 web.config 中可能有类似的内容:

        <compilation debug="true">
            <assemblies>
                <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
                <add assembly="System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
                <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
                <add assembly="System.Web.Abstractions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
                <add assembly="System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
                <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
                <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
                <add assembly="System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
            </assemblies>
        </compilation>
    

    尝试用这个包围它(或整个&lt;system.web&gt; 部分):

    <location path="." inheritInChildApplications="false">
    ....
    </location> 
    

    更多信息here

    【讨论】:

    • 嗯,我的 wwwroot 中有我的 asp.net mvc 应用程序所在的 bin 文件夹,它包含 mvc.dll,它加载得很好。问题是我的虚拟目录有我的 asp.net webservice 不是 asp.net mvc 应用程序,所以它在 bin 文件夹中只有我的 webservice.dll。然而它要求 mvc.dll 这是没有意义的。如果我将 web 服务本身放在 wwwroot 中(所以不是 mvc 的东西)它工作正常。
    • 我刚刚尝试过,即使我的应用程序不使用它,我也必须在我的虚拟目录中使用我使用的每个 bin。这没有任何意义。
    • hmm 我认为它可能正在工作,但我注意到这样做会杀死 Vs2008 中的调试器。如果我的 web.config 中有这一行,我将无法再调试。我拿出来调试一下。
    • @chobo2 - 这可能是因为&lt;compilation debug="true"&gt; 不再被网络服务子网络继承。尝试将 web.config 文件放在该虚拟目录中并添加确保其中包含该部分(当然减去 MVC dll 引用)
    • 您好,网络服务有自己的 web.config 并在其中包含该行。我认为它仍然在网络服务上进行调试。我说的是我的 asp.net mvc 应用程序,它是 web.config(所以是根 web.config)。当我有那行时,我失去了调试器。
    【解决方案2】:

    您的 web.config 文件正在寻找 MVC 文件,请从您的 web.config 中删除此行

    <add assembly="System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    

    谢谢

    ReliableSite.Net

    【讨论】:

    • 是的,它必须在那里,否则我的 asp.net mvc 应用程序将无法工作。
    • 然后将 MVC dll 放入 bin 文件夹中。