Asp.net Core 3.0-无法加载静态文件 - c#

我刚刚部署了一个新的asp.net core 3.0项目,但似乎大多数文件都没有加载,例如boostrap,css文件和大量图像。 (因为网站无处不在)

我浏览了该项目(根解决方案)并将其包含在我的项目中。 (在线删除了整个解决方案,然后一次又一次地重新发布),甚至重启了VS。

这是我的statup.cs

 app.UseStaticFiles(new StaticFileOptions
    {
        FileProvider = new PhysicalFileProvider(
           Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot"))
           ,
        RequestPath = new PathString("/wwwroot")
    });

    app.UseHttpsRedirection();
    app.UseStaticFiles();

但这并没有改变问题

这是浏览器工具。有什么建议吗?

参考方案

我认为您已经在program.cs中错过了这一点
尝试像这样添加

.UseContentRoot(Directory.GetCurrentDirectory())

喜欢

var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.Build();

host.Run();

并在startup.configure中使用UseDirectoryBrowser作为

app.UseDirectoryBrowser(new DirectoryBrowserOptions()
{
    FileProvider = new PhysicalFileProvider(
        Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot\images")),
    RequestPath = new PathString("/MyImages")//this is the folder under 
   images 
});

并在Startup.ConfigureServices中添加AddDirectoryBrowser扩展方法为

public void ConfigureServices(IServiceCollection services)
{
  services.AddDirectoryBrowser();
}

并在startup.cs中添加这样的内容

public void Configure(IApplicationBuilder app, IHostingEnvironment env,    ILoggerFactory loggerFactory)
{
app.UseStaticFiles(); // For the wwwroot folder

app.UseStaticFiles(new StaticFileOptions()
{
    FileProvider = new PhysicalFileProvider(
        Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot\images")),
    RequestPath = new PathString("/MyImages")
});

app.UseDirectoryBrowser(new DirectoryBrowserOptions()
{
    FileProvider = new PhysicalFileProvider(
        Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot\images")),
    RequestPath = new PathString("/MyImages")
});
}

并像这样在您的startup.configure中添加为

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

ASP.NET Core Singleton实例与瞬态实例的性能 - c#

在ASP.NET Core依赖注入中,我只是想知道注册Singleton实例是否会比注册Transient实例更好地提高性能?在我看来,对于Singleton实例,创建新对象和相关对象只需花费一次时间。对于Transient实例,此成本将针对每个服务请求重复。因此Singleton似乎更好。但是,在Singleton上使用Transient时,我们可以获得多…

ASP.NET Core-在Singleton注入上存储库依赖项注入失败 - c#

我正在使用SoapCore为我的ASP.NET Core MVC应用程序创建Web服务。我正在使用Entity Framework Core和简单的存储库模式来获取我的数据库数据。我通过Startup.cs中的.AddSingleton()注入存储库类:services.AddSingleton<IImportRepository, ImportRep…

如何在ASP.NET Core Web应用程序中增加JSON反序列化MaxDepth限制 - c#

我们正在将ASP.NET Core 2.1与.NET Framework 4.6.2结合使用。我们有一个客户需要向我们的Web应用程序发送一个很大程度上嵌套的json结构。当他们进行此调用时,我们将输出以下日志并返回错误: 读取器的MaxDepth超过了32。路径“ super.long.path.to property”,第1行,位置42111。”我浏览了…

ASP.NET Core-使用Windows身份验证进行授权 - c#

我已将我的Web API配置为与Windows身份验证一起使用。我的目标实质上是根据用户的Windows帐户来限制控制器中的某些操作。一些将能够执行读取操作,而其他一些将能够执行将写入基础数据库的操作。我找到了大量有关如何设置基于声明的授权的文档,这是我认为我需要走的路。我还没有找到如何使用Windows身份验证进行设置。我想我缺少中间步骤,例如将Windo…

ASP.NET Core MVC视图组件搜索路径 - c#

在此处的文档中:https://docs.microsoft.com/en-us/aspnet/core/mvc/views/view-components?view=aspnetcore-2.2 运行时在以下路径中搜索视图:/Views/{Controller Name}/Components/{View Component Name}/{View Nam…