【问题标题】:ASP.NET5.0 Add html fileASP.NET5.0 添加html文件
【发布时间】:2016-09-10 01:14:12
【问题描述】:

我有一个 html 文件 index.html,我想将它与我的 asp.net5 项目链接。

我尝试在 wwwroot 中添加 index.html,当我开始调试时,我转到 localhost:port/index.html,但它什么也没显示。

有人可以链接到文档或解释如何做吗?

PS:我用的是visual-studio。

配置代码:

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app)
    {
        app.UseIISPlatformHandler();
        app.Run(async (context) =>
        {

            await context.Response.WriteAsync("test");
        });

    }

【问题讨论】:

    标签: c# html asp.net visual-studio


    【解决方案1】:

    您必须告诉应用您要使用静态文件。例如,您在 Web Api 2.0 服务器中不需要它。因此,默认情况下不添加此项。在您的 Startup.cs 添加 app.UseStaticFiles();到 Configure 方法。

    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
    {    
        app.UseIISPlatformHandler();
        app.UseStaticFiles();
        app.UseMvc();
    }
    

    【讨论】:

    • 您好,谢谢您的回复,但我没有使用静态文件,我只有 app.UseIISPlatformHandler 和 app.UseMiddleware
    • "Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
    • 在你的project.json中添加依赖
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-14
    • 2012-07-03
    • 2015-05-03
    • 2017-10-27
    • 2015-04-29
    相关资源
    最近更新 更多