标签: kestrel-http-server

将index.html设置为asp.net核心中的默认页面

如何从我的wwwroot中获取asp.net核心来提供index.html文件?

我想这样做的原因是因为我使用角度CLI开发了一个角度4应用程序,它负责整个构建过程.我已将其设置为我的asp.net核心项目的wwwroot目录,但asp.net核心不想提供它.

起初我试图通过控制器返回html文件.我尝试过这条路线:

app.UseMvc(routes =>
    {
        routes.MapRoute(
            name: "default",
            template: "{controller=Home}/{action=Index}");
    });
Run Code Online (Sandbox Code Playgroud)

然后在控制器中我返回如下的html文件:

public IActionResult Index()
{
    var webRoot = _env.WebRootPath;
    var path = System.IO.Path.Combine(webRoot, "index.html");

    return File(path, "text/html");
}
Run Code Online (Sandbox Code Playgroud)

这没用.它返回了404未找到的异常并给出了路径,但它给出的路径是index.html文件的正确路径(我将其剪切并粘贴到资源管理器中并打开文件).

我也在启动时声明这些:

app.UseStaticFiles();
app.UseDefaultFiles();
Run Code Online (Sandbox Code Playgroud)

然后我尝试删除默认路由.现在我能够访问index.html文件,但仅当我输入文件名时,即:

本地主机:58420/index.html的

如果我尝试在没有指定"index.html"的情况下访问域的根目录,则会收到404错误.

将index.html作为默认页面引用的正确方法是什么?我猜测从控制器做它可能更好,因为它将与角度路由兼容而无需重写.

c# kestrel-http-server asp.net-core

28
推荐指数
4
解决办法
2万
查看次数

让ASP.Net Core关闭在IISExpress中触发ApplicationStopping事件

我知道有一个先前的问题,还有一个GitHub问题:https://github.com/aspnet/Hosting/issues/846似乎从Microsoft.AspNetCore.Server.IISIntegration 1.1解决.但是,尽管有这个版本,这似乎仍然无法在IISExpress中工作(我通过让它执行Debug.WriteLine并在ApplicationStopping和ApplicationStopped上写入日志文件来测试它).我正在使用工具托盘小部件关闭IISExpress.

我不确定我是否做错了,是否以这种方式关闭IISExpress作为'正常关闭'来触发这些事件.看起来这可能在IIS中运行良好,但你无法在本地使用ASP.Net Core和完整的IIS进行开发,所以我想知道是否有任何方法可以在开发环境中触发这些事件进行测试?

这是Startup.cs中的代码:

public void Configure(IApplicationBuilder app, IApplicationLifetime life, IHostingEnvironment env, ILoggerFactory loggerFactory)
    {
        // other configure code here

        life.ApplicationStopping.Register(() =>
            Debug.WriteLine(">>Stopping"));
        life.ApplicationStopped.Register(() =>
            Debug.WriteLine(">>Stopped"));
    }
Run Code Online (Sandbox Code Playgroud)

c# iis-express kestrel-http-server asp.net-core

25
推荐指数
1
解决办法
2488
查看次数

使用VSCode,DNX和kestrel运行第一个ASP.NET 5应用程序会导致IOException

按照Visual Studio代码文档中描述的步骤,dnx . kestrel在Mac OS X上通过VSCode的命令调色板运行最终命令会在访问http:// localhost:5001时导致IOException :

kqueue() FileSystemWatcher has reached the maximum nunmber of files to watch.
Run Code Online (Sandbox Code Playgroud)

有关完整的堆栈跟踪,请参阅附带的屏幕截图.可能有什么不对?在此输入图像描述

dnx visual-studio-code kestrel-http-server

24
推荐指数
1
解决办法
3034
查看次数

WebListener vs Kestrel:为什么选择一个而不是另一个?优点缺点?

两个独立但相似的服务器的原因是什么?有什么区别?我可以在码头工具中运行吗?两者都支持相同的东西,比如所有身份验证类型?

asp.net kestrel-http-server asp.net-core

24
推荐指数
2
解决办法
7201
查看次数

增加Kestrel的上传请求长度限制

我正在运行ASP.NET Core Web应用程序,并希望上传大文件.

我知道在运行IIS时,可以通过web.config以下方式更改限制:

<httpRuntime maxRequestLength="1048576" /> 
...
<requestLimits maxAllowedContentLength="1073741824" /> 
Run Code Online (Sandbox Code Playgroud)

如何在运行新的ASP.NET Core Kestrel Web服务器时执行等效操作?

我得到了例外情况"申请机构太大了".

file-upload kestrel-http-server asp.net-core asp.net-core-2.0

23
推荐指数
2
解决办法
1万
查看次数

AspNet上的Kestrel vNext不提供/下的索引页面

我需要能够使用Kestrel Web服务器在默认url /下提供我的'index.html' .现在我只能使用完整路径(即/index.html)访问我的静态文件

同样,这在VisualStudio上完美运行,上下文是OSX与Kestrel

这是我的Startup.cs

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

 public void Configure(IApplicationBuilder app)
 {
     app.UseStaticFiles();
     app.UseMvc();
 }
Run Code Online (Sandbox Code Playgroud)

我到目前为止的解决方案是在HomeController中进行重定向.但这很简单,我试图提供一个静态的html文件,老实说我不希望它由我的应用程序处理,如果可能直接从Kestrel服务.

macos asp.net-mvc asp.net-core-mvc kestrel-http-server asp.net-core

22
推荐指数
1
解决办法
3424
查看次数

如何使用Visual Studio ASP.NET Core观察文件更改"dotnet watch"

我使用Visual Studio与ASP.NET Core并使用F5或Ctrl + F5(不直接使用命令行)运行网站.我想使用"dotnet watch"功能来确保动态获取所有更改以避免再次启动服务器.似乎使用命令行你会使用"dotnet watch run",但Visual Studio使用launchSettings.json并在幕后操作,如果我理解正确的话.

如何在那里连接"dotnet手表"?

dnx kestrel-http-server asp.net-core

20
推荐指数
5
解决办法
1万
查看次数

为HTTPS配置ASP.NET Core 2.0 Kestrel

TL; DR今天使用ASP.NET Core 2.0设置HTTPS的正确方法是什么?

我想将我的项目配置为使用https和他们在BUILD 2017中展示的证书.我尝试了几个设置,但没有任何效果.经过一番研究,我更加困惑.看来,有很多方法可以配置URL和端口.我已经看到了appsettings.json,hosting.json通过代码,在launchsettings.json我们还可以设置URL和端口.

有"标准"的方法吗?

这是我的 appsettings.development.json

{
  "Kestrel": {
    "Endpoints": {
      "Localhost": {
        "Address": "127.0.0.1",
        "Port": "40000"
      },
      "LocalhostWithHttps": {
        "Address": "127.0.0.1",
        "Port": "40001",
        "Certificate": {
          "HTTPS": {
            "Source": "Store",
            "StoreLocation": "LocalMachine",
            "StoreName": "My",
            "Subject": "CN=localhost",
            "AllowInvalid": true
          }
        }
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

但是launchsettings.json当我从命令行dotnet run开始或从Visual Studio开始使用调试器时,它始终需要url和port .

这是我Program.csStartup.cs

public class Program
{
    public static void Main(string[] args)
    {
        BuildWebHost(args).Run();
    }

    public …
Run Code Online (Sandbox Code Playgroud)

c# kestrel-http-server asp.net-core asp.net-core-2.0

19
推荐指数
1
解决办法
2万
查看次数

如何解决心跳时间超过“00:00:01”失败的问题?

我有一个执行 HTTP POST 的 .NetCore C# 项目。该项目是在 Kubernetes 中设置的,我注意到以下日志:

Heartbeat took longer than "00:00:01" at "02/22/2020 15:43:45 +00:00".
warn: Microsoft.AspNetCore.Server.Kestrel[22]
      Heartbeat took longer than "00:00:01" at "02/22/2020 15:43:46 +00:00".
warn: Microsoft.AspNetCore.Server.Kestrel[22]
      Heartbeat took longer than "00:00:01" at "02/22/2020 15:43:47 +00:00".
warn: Microsoft.AspNetCore.Server.Kestrel[22]
      Heartbeat took longer than "00:00:01" at "02/22/2020 15:43:48 +00:00".
warn: Microsoft.AspNetCore.Server.Kestrel[22]
      Heartbeat took longer than "00:00:01" at "02/22/2020 15:43:49 +00:00".
warn: Microsoft.AspNetCore.Server.Kestrel[22]
      Heartbeat took longer than "00:00:01" at "02/22/2020 15:43:50 +00:00".
warn: Microsoft.AspNetCore.Server.Kestrel[22]
      Heartbeat took longer than "00:00:01" …
Run Code Online (Sandbox Code Playgroud)

multithreading threadpool kubernetes kestrel-http-server asp.net-core

19
推荐指数
1
解决办法
2万
查看次数

IIS与Kestrel性能比较

与Kestrel http服务器相比,IIS的性能如何?

似乎Kestrel受到异步和事件驱动的服务器框架系列的启发.与此同时,IIS具有悠久的开发历史,并且在功能方面显然更加成熟.综合考虑所有这些因素,我特意寻找内存利用率,线程利用率,请求相关比较(如每秒请求数)和流功能的比较.

iis performance kestrel-http-server

18
推荐指数
3
解决办法
2万
查看次数