为什么DNX运行代码两次

mis*_*ghi 2 .net c# dnx

我想将我的框架移植到新的.net核心,所以我创建了一个空的应用程序,添加了一个静态成员来感受行为,为每个请求增加一个int,但它运行两次,一次用于请求和一旦在请求之后,所以不是得到1,2,3,4 ......我得到1,3,5,7 ......

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);
}
Run Code Online (Sandbox Code Playgroud)

Jim*_*iTh 8

猜测:看看例如Chrome的网络标签(根据您的结果判断,您可能已在Chrome中进行测试).你可能会看到你确实有两个请求:你期望的那个 - 加上一个用于favicon.ico.而你的应用程序正在为这两者提供服务.