Bja*_*eCK 108 c# iis asp.net-mvc asp.net-mvc-4
我刚刚将我的项目发布到Arvixe上的主机并得到此错误(本地工作正常):
Server Error in '/' Application.
Directory does not exist.
Parameter name: directoryVirtualPath
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.ArgumentException: Directory does not exist.
Parameter name: directoryVirtualPath
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.
Stack Trace:
[ArgumentException: Directory does not exist.
Parameter name: directoryVirtualPath]
System.Web.Optimization.Bundle.IncludeDirectory(String directoryVirtualPath, String searchPattern, Boolean searchSubdirectories) +357
System.Web.Optimization.Bundle.Include(String[] virtualPaths) +287
IconBench.BundleConfig.RegisterBundles(BundleCollection bundles) +75
IconBench.MvcApplication.Application_Start() +128
[HttpException (0x80004005): Directory does not exist.
Parameter name: directoryVirtualPath]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +9160125
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +131
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +194
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +339
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +253
[HttpException (0x80004005): Directory does not exist.
Parameter name: directoryVirtualPath]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9079228
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +97
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +256
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.237
Run Code Online (Sandbox Code Playgroud)
这是什么意思 ?
Mar*_*sen 221
我有同样的问题,发现我有一些使用{version}和*通配符指向不存在的文件的包
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js"));
Run Code Online (Sandbox Code Playgroud)
我删除了所有这些,错误就消失了.
dsn*_*nez 16
我有同样的问题,这不是代码问题.我使用的是发布选项(不是FTP版本),Visual Studio没有将我的一些脚本/ css上传到azure服务器,因为它们没有"包含在我的项目中".所以,在本地它工作得很好,因为文件存在于我的硬盘中.在我的案例中解决这个问题的是"项目>显示所有文件......"并右键单击未包含的文件,包含它们并再次发布
这是我写的一个快速课程,以使这更容易.
using System.Web.Hosting;
using System.Web.Optimization;
// a more fault-tolerant bundle that doesn't blow up if the file isn't there
public class BundleRelaxed : Bundle
{
public BundleRelaxed(string virtualPath)
: base(virtualPath)
{
}
public new BundleRelaxed IncludeDirectory(string directoryVirtualPath, string searchPattern, bool searchSubdirectories)
{
var truePath = HostingEnvironment.MapPath(directoryVirtualPath);
if (truePath == null) return this;
var dir = new System.IO.DirectoryInfo(truePath);
if (!dir.Exists || dir.GetFiles(searchPattern).Length < 1) return this;
base.IncludeDirectory(directoryVirtualPath, searchPattern);
return this;
}
public new BundleRelaxed IncludeDirectory(string directoryVirtualPath, string searchPattern)
{
return IncludeDirectory(directoryVirtualPath, searchPattern, false);
}
}
Run Code Online (Sandbox Code Playgroud)
要使用它,只需在代码中将BundBundle替换为BundleRelaxed,如下所示:
bundles.Add(new BundleRelaxed("~/bundles/admin")
.IncludeDirectory("~/Content/Admin", "*.js")
.IncludeDirectory("~/Content/Admin/controllers", "*.js")
.IncludeDirectory("~/Content/Admin/directives", "*.js")
.IncludeDirectory("~/Content/Admin/services", "*.js")
);
Run Code Online (Sandbox Code Playgroud)