.Net Core 的http请求问题
使用 vs for mac 生成的.net站点,其中
Startup.cs:
namespace vs_core_web
{
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.Run(async (context) =>
{
await (new testClass()).OutPutString(context); // 此处是会返回当前 testClass 类初始化的次数
});
}
}
}
namespace vs_core_web
{
public class testClass
{
static int runtimes = 0;
public testClass()
{
runtimes++;
}
public Task OutPutString(HttpContext context)
{
return context.Response.WriteAsync("Hello World!"+ runtimes.ToString());
}
}
}
await (new testClass()).OutPutString(context); 这一个部分的代码,请求一次http,会触发两次,是什么情况,有人知道么?
干净的新项目也是一样这个问题...
求教~
页面请求的结果(多次):
Hello World!1
Hello World!3
Hello World!5
Hello World!7
.....
尾数永远是单数