【问题标题】:css and js always return 404 local [closed]css 和 js 总是返回 404 local [关闭]
【发布时间】:2019-12-03 09:43:57
【问题描述】:

我在 css 文件夹和 js 文件夹的 wwwroot 中添加样式表和 JavaScript,当我尝试在 layout.chtml 中使用它时,它总是返回 404this example of my wwwrot

startup.cs

   ` 
    public IConfiguration Configuration { get; }

    public void ConfigureServices(IServiceCollection services)
    {

        services.AddMvc();
        services.AddMemoryCache();
        services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
    }


    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        app.Use(next => context =>
        {
            if (string.Equals(context.Request.Headers["X-Forwarded-Proto"], "https", StringComparison.OrdinalIgnoreCase))
            {
                context.Request.Scheme = "https";
            }

            return next(context);
        });
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseExceptionHandler("/Home/Error");
            app.UseHsts();
        }
        app.UseSession();
        app.UseAuthentication();
        app.UseMvc();


}`

【问题讨论】:

  • 您能否将Configure 中的Startup.cs 方法包含在内?

标签: c# css web core


【解决方案1】:

请在Startup.cs中添加UseStaticFiles

public void Configure(IApplicationBuilder app)
{
    app.UseStaticFiles();
}

【讨论】:

    猜你喜欢
    • 2014-03-24
    • 1970-01-01
    • 2021-08-05
    • 2015-07-31
    • 2020-02-09
    • 1970-01-01
    • 1970-01-01
    • 2021-08-01
    • 2020-09-04
    相关资源
    最近更新 更多