【问题标题】:How to get the process name iisexpress instead of dotnet in asp.net core 2.2如何在asp.net core 2.2中获取进程名称iisexpress而不是dotnet
【发布时间】:2019-11-09 09:13:29
【问题描述】:

我在浏览器中执行时正在学习 asp.net 核心,我得到的响应标头有 kestrel 而不是 iisexpress。我在 Startup.cs 配置方法中编写了以下代码来获取进程名称,但我仍然得到 dotnet 我无法获取 iisexpress。

app.Run(async (context) => {
  await context.Response.WriteAsync("Hello World!\n");
  await context.Response.WriteAsync(System.Diagnostics.Process.GetCurrentProcess().ProcessName);//dotnet             
});

在 Program.cs 我添加 .UseIIS()

public static IWebHostBuilder CreateWebHostBuilder(string[] args) => 
  WebHost.CreateDefaultBuilder(args)
    .UseIIS()
    .UseStartup<Startup>();

以下来自 .csproj 文件

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
<RootNamespace>CookieStore</RootNamespace>
</PropertyGroup>

请帮助我在 InProcess 和 OutOfProcess 中运行项目。

【问题讨论】:

  • “我无法获取 iisexpress”:但是当我使用 Visual Studio (ASP.NET Core 2.2) 运行它时,我得到了 iisexpress。有没有重现的demo?

标签: asp.net-core asp.net-core-2.2


【解决方案1】:

如果您使用“dotnet run”从 CLI 运行应用程序,默认情况下它将在 kestrel 中运行,如果您使用 Visual Studio,请尝试从启动下拉菜单中使用 IIS Express 运行应用程序。

【讨论】:

  • 我在 Windows 10 家庭版中使用 Visual Studio 2017,但我仍然只有 dotnet。
  • 确保您的 launchsettings.json 有一个 IISExpress 条目
  • 我的 launchSettings.json 是 IISExpress。检查以下代码。
    "profiles": { "IIS Express": { "commandName": "IISExpress", "launchBrowser": true, "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } }
【解决方案2】:

今天终于解决了,在我更新了我的Visual Studio 2017之后。之前我用VS2017 15.3更新到VS2017 15.9,问题已经解决了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-12-30
    • 2020-01-04
    • 1970-01-01
    • 2020-11-26
    • 1970-01-01
    • 2020-11-12
    • 2018-01-16
    相关资源
    最近更新 更多