我能够运行我编写的控制台Web应用程序而没有任何问题,并获得所需的输出,该输出将消息显示回命令提示符。
但是,我现在已经将此Web应用程序引用到控制台应用程序中,并且现在出现标题中描述的错误。
我尝试从“证书-当前用户”和“证书-受信任的根证书颁发机构”中手动从MMC删除localhost
证书。我还尝试进入Visual Studio命令提示符并执行dotnet dev-certs https --clean
然后执行dotnet dev-certs https`` as well as
dotnet dev-certs https --trust``我也使用verbose
执行了,但这并没有改变结果。
我还修复了IIS 10.0 Express并重新启动了笔记本电脑,以获取IIS Express Development Certificate
控制台应用C#(Program.cs):
namespace Rapiscan264_3
{
class Program
{
static void Main(string[] args)
{
string[] argsWeb = new string[] { "192.168.2.2","1234" };
WebApplication1.Program.Main(argsWeb);
;
}
}
}
Web App C#(Program.cs):
namespace WebApplication1
{
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine($"HALO REST Server Simulator Copyright 2019\n");
IPAddress ipAddress = IPAddress.Parse("192.168.2.2");
int port = 1234;
if (args.Length < 2)
{
Console.WriteLine($"*ERROR* - Number of Arguments Passed to Startup Incorrect,Expected 2 but Received { args.Length }!\n");
}
else
{
if (!IPAddress.TryParse(args[0],out ipAddress))
{
Console.WriteLine($"*ERROR* - Invalid IP Address Configured,IP={ args[0] }\n");
}
if (!int.TryParse(args[1],out port))
{
Console.WriteLine($"*ERROR* - Invalid Port Configured,Port={ args[1] }\n");
}
}
string url = $"https://{ ipAddress.ToString() }:{ port.ToString() }";
Console.WriteLine($"Starting REST Server with URL = { url }\n");
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseUrls("https://192.168.2.2:1234")
.UseStartup<Startup>();
}
}
Startup.cs:
namespace WebApplication1
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app,IHostingEnvironment env)
{
env.EnvironmentName = "Development";
env.WebRootPath = "C:\\Users\\jch\\source\\repos\\Rapiscan264-3\\WebApplicationSourceCode\\wwwroot";
env.ContentRootPath = "C:\\Users\\jch\\source\\repos\\Rapiscan264-3\\WebApplicationSourceCode";
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
}
app.UseMvc();
}
}
}
仅在没有控制台应用程序的情况下重申一下,或者将Web应用程序设置为启动应用程序就可以正常工作,通常情况下,我会提供预期的结果,但这只是控制台应用程序中的很多文字。
我认为问题与证书有关,或者可能是我看不到的冲突。
编辑:我还应该提到我在Windows 10上。当我执行```.dotnet dev-certs https --check`时,我收到消息“找到了有效的证书。”