我正在尝试按照GitHub使用 OIDC 实现单点登录,但我不断收到错误:
“WebHostBuilder”不包含“UseKestrel”的定义,并且找不到接受“WebHostBuilder”类型的第一个参数的可访问扩展方法“UseKestrel”(您是否缺少 using 指令或程序集引用?)
实现SystemBrowser.cs代码时
using IdentityModel.OidcClient.Browser;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using System;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
//other code
//simplified code extract below
IWebHost _host = new WebHostBuilder()
.UseKestrel()
.UseUrls(_url)
.Configure(Configure)
.Build();
//other code
Run Code Online (Sandbox Code Playgroud)
据此,它应该是 Microsoft.AspNetCore.Hosting 的一部分?
我是否缺少某些内容或需要安装 NuGet 包?到目前为止安装的软件包有:
任何援助将不胜感激。
ASP.NET Core 5 MVC 应用程序在 Debian Linux 中使用 Weboptimizer ( https://github.com/ligershark/WebOptimizer )。
在startUp.cs中我有:
public void ConfigureServices(IServiceCollection services)
{
...
services.AddWebOptimizer();
...
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
...
app.UseWebOptimizer();
...
}
Run Code Online (Sandbox Code Playgroud)
syslog 包含大量信息消息,例如
4 月 18 日 09:12:26 c202-76 kestrel-store[28711]:#033[40m#033[32minfo#033[39m#033[22m#033[49m: WebOptimizer.AssetMiddleware][1000]
4 月 18 日 09:12:26 c202-76 kestrel-store[28711]:请求已开始 '/css/siteerp.css' 4 月 18 日 09:12:26 c202-76 kestrel-store[28711]:#033[40m# 033[32minfo#033[39m#033[22m#033[49m: WebOptimizer.AssetBuilder][1001]
4 月 18 日 09:12:26 c202-76 kestrel-store[28711]:从内存缓存响应“/css/siteerp.css”
4 月 18 日 09:12:26 c202-76 kestrel-store[28711]:#033[40m#033[32minfo#033[39m#033[22m#033[49m: WebOptimizer.AssetMiddleware][1000]
4 月 18 日 09:12:26 …
asp.net-core-mvc .net-core kestrel-http-server asp.net-core weboptimizer
运行新创建的基于IdentityServer4 Asp.Net Core的服务器.它"工作"的意义是它在没有HTTPS的情况下工作,无论是在进行身份验证的调用中还是为了提供一些Asp.Net MVC视图.我将其切换为使用HTTPS进行本地开发环境,根据本文生成证书.
从浏览器,它"工作".我能够像Chrome那样的文章建议并绕过安全警告来获取Web视图.但是,从.Net客户端我使用IdentityModel NuGet包,只是尝试使用Discovery Endpoint访问元数据现在失败了.服务器提供"无法验证HTTPS连接"IOException,并且客户端提供"证书颁发机构无效或不正确"HttpRequestException.
我猜这与浏览器中的事物是交互式的事实有关,我可以告诉它忽略警告并继续.但是在代码中,特别是使用该库,它给了我异常而不是继续.也许.
有没有办法处理这种使用HTTPS和自签名证书更好地运行IdentityServer4/AspNetCore的方案?有没有可以用DiscoveryClient做的事情,我没有看到?
这个问题很相似,但在这种情况下重新生成证书并没有帮助.我想知道IdentityServer/DiscoveryClient角度是否还有其他原因或见解.
我在 VS 2017 中使用 ASP.NET Core。我想知道构建的应用程序是否同时创建IIS Express and Kestrel?还是只是其中之一?我只是在本地说话。
我有一个带有以下代码的应用程序 .NET core 2.1:
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseStaticFiles();
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(
Path.Combine(Directory.GetCurrentDirectory(), "Assets")),
RequestPath = "/Assets"
});
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseMvc();
}
Run Code Online (Sandbox Code Playgroud)
和我的结构文件夹:
但这些网址都没有打开图像:
“my-website.com/images/snes/alien.jpg”
“my-website.com/wwwroot/images/snes/alien.jpg”
“my-website.com/Assets/Snes/alien.jpg”
有人知道出了什么问题吗?
编辑:这是 CurrentDirectoy() 方法获取的文件夹(显然是正确的):
Edit2:使用此代码在 localhost 上工作,但在我在 azure 上发布时却没有:
app.UseFileServer(
new FileServerOptions()
{
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot"))
});
Run Code Online (Sandbox Code Playgroud) 我正在使用Asp.Net Core 2.2.1。我正在尝试从响应中删除服务器标头。我尝试options.AddServerHeader = false;在内部添加ConfigureKestrel(),但仍未成功。请协助我解决问题。
这是我的代码:
Program.cs
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args)
{
return WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.ConfigureKestrel((context,options) => {
// Set properties and call methods on options
options.AddServerHeader = false;
});
}
}
Run Code Online (Sandbox Code Playgroud)
Web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!-- To customize the asp.net core module uncomment and edit the following section.
For more info see https://go.microsoft.com/fwlink/?linkid=838655 -->
<system.webServer>
<security>
<requestFiltering removeServerHeader="true" /> …Run Code Online (Sandbox Code Playgroud) c# response-headers kestrel kestrel-http-server asp.net-core
我有一个 ASP.NET Core (3.1) 应用程序,它是自托管的并作为服务运行。我想为其公开一个 HTTPS 端点。在同一台计算机上安装了一个 IIS,其中已配置了 https 和证书:

我还可以通过 powershell 列出它:
> get-childitem cert:\LocalMachine\My\ | format-table NotAfter, Subject
NotAfter Subject
-------- -------
27.10.2023 07:38:45 <irrelevant>
08.03.2022 09:52:44 CN=a7642e58-2cdf-4e9b-a277-60fad84d7c64, DC=3336d6b0-b132-47ee-a49b-3ab470a5336e
23.02.2022 21:51:53 CN=a7642e58-2cdf-4e9b-a277-60fad84d7c64, DC=3336d6b0-b132-47ee-a49b-3ab470a5336e
27.10.2031 06:48:06 CN=a7642e58-2cdf-4e9b-a277-60fad84d7c64
26.10.2024 10:41:03 E=****.com, CN=****, OU=IT, O=****, L=****, S=***, C=**
Run Code Online (Sandbox Code Playgroud)
我更改了 appsettings.json 以使用商店中的证书:
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Warning"
}
},
"AllowedHosts": "*",
"Kestrel": {
"EndPoints": {
"Http": {
"Url": "http://*:5000"
},
"HttpsDefaultCert": {
"Url": "https://*:5001"
} …Run Code Online (Sandbox Code Playgroud) ssl ssl-certificate kestrel-http-server asp.net-core .net-core-3.1
asp.net-core ×7
c# ×3
.net-core ×2
asp.net ×1
https ×1
iis-express ×1
kestrel ×1
ssl ×1
weboptimizer ×1
wpf ×1