【问题标题】:MVC6 Self-Hosted wwwroot content returns 404, IIS Express doesn'tMVC6 自托管 wwwroot 内容返回 404,IIS Express 不返回
【发布时间】:2015-04-09 14:18:05
【问题描述】:

我正在使用 ASP.NET5/MVC6 并构建了一个小型 Web 应用程序。当我使用 Visual Studio 的 IIS Express 调试服务器时,一切都按预期工作。但是当我使用“web”服务器配置文件,即 WebListener 服务器时,只有我的 MVC 控制器和视图工作。但是,存储在“wwwroot”下的所有内容都会返回 404。我放在那里的是 CSS、JS 和图像文件。

一旦我切换回 IIS Express,内容就会正确获取。

完整的源代码在这里:https://github.com/acastaner/acastaner.fr-mvc6

这是我的 Startup 课程:

public class Startup
    {
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
        }

        public void Configure(IApplicationBuilder app)
        {
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller}/{action}/{id?}",
                    defaults: new { controller = "Home", action = "Index" });
            });
        }
    }

这是我的 project.json 文件:

{
    "webroot": "wwwroot",
    "version": "1.0.0-*",
    "dependencies": {
        "Microsoft.AspNet.Server.IIS": "1.0.0-beta3",
        "Microsoft.AspNet.Diagnostics": "1.0.0-beta3",
        "Microsoft.AspNet.Mvc": "6.0.0-beta3",
        "Microsoft.AspNet.Server.WebListener": "1.0.0-beta3"
    },
    "frameworks": {
        "aspnet50": { },
        "aspnetcore50": { }
    },
    "bundleExclude": [
        "node_modules",
        "bower_components",
        "**.kproj",
        "**.user",
        "**.vspscc"
    ],
    "exclude": [
        "wwwroot",
        "node_modules",
        "bower_components"
    ],
    "commands": {
        "web ": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5000"
    }
}

我将 Razor 用于视图,这是我如何引用文件的示例:

<link href="~/css/bootstrap.min.css" rel="stylesheet" type="text/css">

有什么我完全错过的明显的东西吗?

编辑:

我确实尝试过使用@Url.Content("~/css/bootstrap.min.css"),但效果是一样的。

【问题讨论】:

  • 我认为 IIS 尚未连接。我认为您现在必须使用 IIS Express,而 VS 仍在 CTP 中
  • 但我正在尝试使用自托管(即:应用程序作为控制台启动),而不是 IIS?
  • 我想我和你有同样的问题......只有一个未修改(字面意思)的 MVC 6 网站预览项目:stackoverflow.com/questions/31060193/…

标签: asp.net-mvc owin asp.net-core asp.net-core-mvc


【解决方案1】:

我认为您还需要一个依赖项:"Microsoft.AspNet.StaticFiles": "1.0.0-beta3"app.UseStaticFiles();app.UseMvc 之前

【讨论】:

  • 就是这样,谢谢! (抱歉验证您的答案延迟,我正在旅行)
猜你喜欢
  • 2015-06-12
  • 1970-01-01
  • 1970-01-01
  • 2015-06-05
  • 2017-08-23
  • 1970-01-01
  • 2018-12-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多