静态文件不是通过IIS提供的,而是通过本地主机提供的-ASP.NET Core 3.1 MVC&C# [英] Static file not served through IIS but serving through localhost - ASP.NET Core 3.1 MVC & C#

查看:67
本文介绍了静态文件不是通过IIS提供的,而是通过本地主机提供的-ASP.NET Core 3.1 MVC&C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是编程的新手,我能够自己解决大部分问题.但是这个问题困扰着我.

I am new to programming, and I was able to solve most of the issues all by myself. But this issue goes over my head.

我正在使用Visual Studio在本地运行我的应用程序.当我在VS中单击"IIS Express"以运行该应用程序时,该应用程序正在使用URL http://localhost:1234/的浏览器中打开并提供静态文件.

I am using Visual Studio to run my app locally. When I click on "IIS Express" within VS to run the app, the app is opening in a browser with url http://localhost:1234/ and serving static files.

但是,当我使用IIS托管应用程序时,例如在浏览器中键入 myapp.com 时,我会看到纯文本的网站.并且没有提供任何静态文件(css,js).

However when I use IIS to host my app, like when I type myapp.com in my browser, I am seeing website in plain text. And no static files (css, js) are being served.

不确定是什么原因导致了该问题.我在Google上搜索了很长时间,并阅读了很多文章,但是其中大多数都要求检查IIS是否已启用静态角色服务,或者建议在 startup.cs <中使用 app.UseStaticFiles()/code>文件.就我而言,这已经完成了.

Not sure what is causing the issue. I googled for long time and read lot of posts, but most of them are asking to check if IIS has static role service turned or suggesting to use app.UseStaticFiles() within startup.cs file. Which in my case is done.

program.cs:

program.cs:

public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
              .ConfigureWebHostDefaults(webBuilder =>
              {
                  webBuilder.UseStartup<Startup>();
              })

Startup.cs:

Startup.cs:

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

我们非常感谢您的帮助.

Any help is much appreciated.

推荐答案

我不知道当我们将其从Visual Studio发布到文件和文件夹"时,我们在Visual Studio中所做的任何更改都不会传递到已发布的文件夹中.由于这个原因"app.UseStaticFiles();"命令(我在发布后写的)不会传递到已发布的文件夹.我必须删除已发布的文件夹,然后重新发布才能使所有工作正常.

I didnt know that when we publish it to "files and folder" from Visual studio, any changes that we make in Visual studio will not go through to published folder. Because of this reason "app.UseStaticFiles();" command (that I wrote after publishing) is not passed on to published folder. I had to delete the published folder and republish to make everything work fine.

这篇关于静态文件不是通过IIS提供的,而是通过本地主机提供的-ASP.NET Core 3.1 MVC&amp;C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆