c# - 红隼定制
问题描述
UseKestrel
尝试使用ASP.NET Core 2.2(在 Windows 10 上运行)中的中间件自定义 Kestrel 时,我无法运行我的网站。
public static IWebHostBuilder CreateWebHostBuilder(string[] args)
{
return new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.ConfigureAppConfiguration((hostingContext, config) =>
{
var env = hostingContext.HostingEnvironment;
config.SetBasePath(env.ContentRootPath);
config.AddInMemoryCollection(new[]
{
new KeyValuePair<string,string>("the-key", "the-value")
})
.AddJsonFile("appsettings.json", reloadOnChange: true, optional: false)
.AddJsonFile($"appsettings.{env}.json", optional: true)
.AddEnvironmentVariables();
})
.ConfigureLogging((hostingContext, logging) =>
{
logging.AddDebug();
logging.AddConsole();
})
.UseIISIntegration()
.UseDefaultServiceProvider((context, options) =>
{
options.ValidateScopes = context.HostingEnvironment.IsDevelopment();
})
.UseStartup<Startup>();
}
我没有收到错误消息,但我的网站无法加载。
解决方案
你能试试这个,看看会发生什么 -
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args)
{
return WebHost.CreateDefaultBuilder(args)
.UseContentRoot(Directory.GetCurrentDirectory())
.UseKestrel(options =>
{
options.Listen(IPAddress.Parse(0.0.0.0), Convert.ToInt32(5000));
})
.UseUrls("0.0.0.0:5000")
.UseStartup<Startup>();
}
推荐阅读
- angular - 从组件中的 observable 获取属性
- reactjs - 异步操作失败后推送到历史记录
- shell - grep if word value greater than value
- r - How do I make this 'mutate' sentences using loop or other functions in R?
- css - 如何使Vuetify网格与内部组件高度相同
- c# - How do i connect my two models to allow cards to be entered into a deck?
- python - 如何用条件元素组成一个列表
- c# - 尝试注册时出现 Microsoft.AspNetCore.Identity.IdentityError
- javascript - 在 javascript/typescript 代码中为云功能设置超时
- html - 如何在 WordPress 的 weglot 插件的下拉按钮中获得圆角边框?