Mono MVC3 无法映射路径

发布于 2024-12-19 07:00:50 字数 2705 浏览 2 评论 0原文

我正在尝试让 MVC3 应用程序在单声道下工作,一切都很顺利,直到我部署到我的服务器上...

我当前收到:

Failed to map path '/projects/_ViewStart.cshtml'

System.InvalidOperationException: Failed to map path '/projects/_ViewStart.cshtml'
  at System.Web.HttpRequest.MapPath (System.String virtualPath, System.String baseVirtualDir, Boolean allowCrossAppMapping) [0x00000] in <filename unknown>:0 
  at System.Web.HttpRequest.MapPath (System.String virtualPath) [0x00000] in <filename unknown>:0 
  at System.Web.Hosting.HostingEnvironment.MapPath (System.String virtualPath) [0x00000] in <filename unknown>:0 
  at System.Web.Hosting.DefaultVirtualPathProvider.FileExists (System.String virtualPath) [0x00000] in <filename unknown>:0 
  at System.Web.WebPages.FileExistenceCache.FileExists (System.String virtualPath) [0x00000] in <filename unknown>:0 
  at System.Web.WebPages.VirtualPathFactoryManager.PageExistsInVPP (System.String virtualPath, Boolean useCache) [0x00000] in <filename unknown>:0 
  at System.Web.WebPages.VirtualPathFactoryManager.PageExists (System.String virtualPath, Boolean useCache) [0x00000] in <filename unknown>:0 
  at System.Web.WebPages.WebPageExecutingBase.FileExists (System.String path, Boolean useCache) [0x00000] in <filename unknown>:0 
  at System.Web.WebPages.StartPage.GetStartPage (System.Web.WebPages.WebPageRenderingBase page, System.String fileName, IEnumerable`1 supportedExtensions) [0x00000] in <filename unknown>:0 
  at System.Web.Mvc.RazorView.RenderView (System.Web.Mvc.ViewContext viewContext, System.IO.TextWriter writer, System.Object instance) [0x00000] in <filename unknown>:0 
  at System.Web.Mvc.BuildManagerCompiledView.Render (System.Web.Mvc.ViewContext viewContext, System.IO.TextWriter writer) [0x00000] in <filename unknown>:0 
  at System.Web.Mvc.ViewResultBase.ExecuteResult (System.Web.Mvc.ControllerContext context) [0x00000] in <filename unknown>:0 
  at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult (System.Web.Mvc.ControllerContext controllerContext, System.Web.Mvc.ActionResult actionResult) [0x00000] in <filename unknown>:0 
  at System.Web.Mvc.ControllerActionInvoker+<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19 () [0x00000] in <filename unknown>:0 
  at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter (IResultFilter filter, System.Web.Mvc.ResultExecutingContext preContext, System.Func`1 continuation) [0x00000] in <filename unknown>:0 

错误。我可以确认所有文件和 DLL 都存在,但路径看起来不正确,它肯定应该在确实存在的 Views 文件夹中查找?

我是否需要进行某种设置以确保它看起来在正确的视图位置?我还注意到文件路径之前没有“~”字符...

我环顾网络并尝试了各种解决方案,但似乎没有一个有效。

I'm trying to get a MVC3 application working under mono, and everything was going well until I deployed to my server...

I'm currently getting:

Failed to map path '/projects/_ViewStart.cshtml'

System.InvalidOperationException: Failed to map path '/projects/_ViewStart.cshtml'
  at System.Web.HttpRequest.MapPath (System.String virtualPath, System.String baseVirtualDir, Boolean allowCrossAppMapping) [0x00000] in <filename unknown>:0 
  at System.Web.HttpRequest.MapPath (System.String virtualPath) [0x00000] in <filename unknown>:0 
  at System.Web.Hosting.HostingEnvironment.MapPath (System.String virtualPath) [0x00000] in <filename unknown>:0 
  at System.Web.Hosting.DefaultVirtualPathProvider.FileExists (System.String virtualPath) [0x00000] in <filename unknown>:0 
  at System.Web.WebPages.FileExistenceCache.FileExists (System.String virtualPath) [0x00000] in <filename unknown>:0 
  at System.Web.WebPages.VirtualPathFactoryManager.PageExistsInVPP (System.String virtualPath, Boolean useCache) [0x00000] in <filename unknown>:0 
  at System.Web.WebPages.VirtualPathFactoryManager.PageExists (System.String virtualPath, Boolean useCache) [0x00000] in <filename unknown>:0 
  at System.Web.WebPages.WebPageExecutingBase.FileExists (System.String path, Boolean useCache) [0x00000] in <filename unknown>:0 
  at System.Web.WebPages.StartPage.GetStartPage (System.Web.WebPages.WebPageRenderingBase page, System.String fileName, IEnumerable`1 supportedExtensions) [0x00000] in <filename unknown>:0 
  at System.Web.Mvc.RazorView.RenderView (System.Web.Mvc.ViewContext viewContext, System.IO.TextWriter writer, System.Object instance) [0x00000] in <filename unknown>:0 
  at System.Web.Mvc.BuildManagerCompiledView.Render (System.Web.Mvc.ViewContext viewContext, System.IO.TextWriter writer) [0x00000] in <filename unknown>:0 
  at System.Web.Mvc.ViewResultBase.ExecuteResult (System.Web.Mvc.ControllerContext context) [0x00000] in <filename unknown>:0 
  at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult (System.Web.Mvc.ControllerContext controllerContext, System.Web.Mvc.ActionResult actionResult) [0x00000] in <filename unknown>:0 
  at System.Web.Mvc.ControllerActionInvoker+<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19 () [0x00000] in <filename unknown>:0 
  at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter (IResultFilter filter, System.Web.Mvc.ResultExecutingContext preContext, System.Func`1 continuation) [0x00000] in <filename unknown>:0 

Errors. I can confirm that all the files and DLL's exist, but the path doesn't look right, surely it should be looking in the Views folder where things DO exist?

Is there some sort of setting I need to set to ensure that it looks in the correct Views location? I also notice there is no "~" character before the file path...

I've looked around the net and tried various solutions, but none seem to work..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

薄暮涼年 2024-12-26 07:00:50

看看你的 Apache 配置,对我来说它说

运行'/usr/bin/mod-mono-server2 --filename /tmp/mod_mono_server_bla --applications /testmono:/var/www/ModMonoMvc3Application --nonstop 失败 (null) (null) (null) (null) (空)(空)(空)'。原因:没有该文件或目录

,因为我误解了配置选项AddMonoApplications。它应该是这样的:

# "default" is defined in mods-available/mod_mono.conf
AddMonoApplications default "/testmono:/var/www/ModMonoMvc3Application"

<Location /testmono/>
    SetHandler mono
</Location>

我不小心写了“bla”而不是“default”,因为我认为这是应用程序名称,但实际上它定义了启动哪个服务器可执行文件。

Have a look into your Apache configuration, for me it said

Failed running '/usr/bin/mod-mono-server2 --filename /tmp/mod_mono_server_bla --applications /testmono:/var/www/ModMonoMvc3Application --nonstop (null) (null) (null) (null) (null) (null) (null)'. Reason: No such file or directory

because I misunderstood the configuration option AddMonoApplications. It should read something like this:

# "default" is defined in mods-available/mod_mono.conf
AddMonoApplications default "/testmono:/var/www/ModMonoMvc3Application"

<Location /testmono/>
    SetHandler mono
</Location>

I accidentally wrote "bla" instead of "default" because I thought it was the application name, but in fact it defines which server executable is started.

又怨 2024-12-26 07:00:50

时出现相同的错误

直接调用HttpContext.Current.Server.MapPath("/")

HttpContext.Current.Server.MapPath(Path.DirectorySeparatorChar.ToString()) 

或但是这有效:

HttpContext.Current.Server.MapPath("~")

I was getting the same error when directly calling

HttpContext.Current.Server.MapPath("/") or

HttpContext.Current.Server.MapPath(Path.DirectorySeparatorChar.ToString()) 

However this works:

HttpContext.Current.Server.MapPath("~")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文