我想将我的框架移植到新的.net核心,所以我创建了一个空应用程序,添加了一个静态成员以了解行为,为每个请求增加一个int,但它运行两次,一次针对该请求,一次在请求之后,所以我得到了1,3,5,7而不是1,2,3,4 ...
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 http://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)
{
app.UseIISPlatformHandler();
app.Run(async (context) =>
{
state++;
await context.Response.WriteAsync(state.ToString());
});
}
public static int state;
// Entry point for the application.
public static void Main(string[] args) => Microsoft.AspNet.Hosting.WebApplication.Run<Startup>(args);
}
猜测:在Chrome之类的“网络”标签中查看(从结果来看,您可能已经在Chrome中进行了测试)。您可能会看到您实际上确实有两个请求:您期望的一个-加上favicon.ico的一个。而您的应用程序将同时提供这两种服务。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句