我有一个默认网站,可以在MacOS上正常运行
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
但是我需要运行Websockets和MVC代码,但是以下Kestrel配置不允许我在端口500001上查看index.html
如何为MacOS上的MVC和Websocket正确配置(学习方法)?
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost
.CreateDefaultBuilder(args)
// Increase Shutdown timeout to accomodate background tasks.
//.UseShutdownTimeout(TimeSpan.FromSeconds(10))
.UseStartup<Startup>()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseKestrel((hostingContext, options) =>
{
if (hostingContext.HostingEnvironment.IsDevelopment())
{
options.Listen(IPAddress.Loopback, 50001, listenOptions =>
{
listenOptions.UseHttps("localhost.p12", "1234");
});
}
});
答案 0 :(得分:0)
配置ASP.NET本身是在您的Startup
类中进行的(您已经用UseStartup<Startup>()
指定了该类,而不是在Program
类中进行了
打开您的Startup.cs
文件,并确保您拥有:
UseStaticFiles()
来提供诸如index.html
之类的静态文件(index.html
既不是ASP.NET MVC的Razor View也不是Razor Page,因为它们具有扩展名.cshtml
和通常以TitleCase
中相应的控制器动作来命名。UseMvc()
以使用具有Controller
和Razor View支持的ASP.NET Core MVC系统。