我有一个 WPF 应用程序,它启动一个 ASP.NET 核心 WEB API 应用程序。
当我使用这些配置启动 WEB API 项目作为启动项目时,它适用于 HTTPS。但是,当我尝试从 WPF 环境启动此应用程序时,它不适用于 HTTPS。
配置:
- Web API 配置:
- 在 Startup.cs 文件中:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.Configure<MvcOptions>(options =>
{
options.Filters.Add(new RequireHttpsAttribute());
});
}
Run Code Online (Sandbox Code Playgroud)
Main 方法如下所示:
public static void InitHttpServer()
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.UseUrls("https://localhost:44300/")
//.UseApplicationInsights()
.Build();
host.Run();
}
Run Code Online (Sandbox Code Playgroud)
当我使用 netstat 命令检查端口时,它显示:
邮递员说:
应用程序中操作方法的调试器都没有被命中。
PS:当我恢复对 HTTPS 的更改并尝试使用 HTTP 时,它工作正常。
HTTP 的主要方法具有不同的端口,并且没有上面提到的配置更改。
我有一个多线程环境,其中应用程序从WPF启动,它启动2个后台工作线程,一个Web套接字服务器和一个Web API服务器.
我想在一个日志文件中记录所有事件.我正在使用log4Net(第一次).
我正在创建3个Logger实例,并假设文件追加器将理解它必须只写入单个文件.
码:
记录器类:
public class Logger :ILogger
{
private static ILog log = null;
static Logger()
{
log = LogManager.GetLogger(typeof(Logger));
GlobalContext.Properties["host"] = Environment.MachineName;
}
public Logger(Type logClass)
{
log = LogManager.GetLogger(logClass);
}
#region ILogger Members
public void LogException(Exception exception)
{
if (log.IsErrorEnabled)
log.Error(string.Format(CultureInfo.InvariantCulture, "{0}", exception.Message), exception);
}
public void LogError(string message)
{
if (log.IsErrorEnabled)
log.Error(string.Format(CultureInfo.InvariantCulture, "{0}", message));
}
public void LogWarningMessage(string message)
{
if (log.IsWarnEnabled)
log.Warn(string.Format(CultureInfo.InvariantCulture, "{0}", message));
}
public void LogInfoMessage(string message)
{
if (log.IsInfoEnabled)
log.Info(string.Format(CultureInfo.InvariantCulture, …Run Code Online (Sandbox Code Playgroud)