为什么 DNX 运行 编码两次
Why is DNX running code twice
我想将我的框架移植到新的 .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);
}
猜测一下:查看例如Chrome(根据您的结果判断,您可能已经在 Chrome 中进行了测试)。您可能会发现您实际上有两个请求:您期望的一个 - 加上 favicon.ico 的一个。而您的应用正在为这两者提供服务。
我想将我的框架移植到新的 .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);
}
猜测一下:查看例如Chrome(根据您的结果判断,您可能已经在 Chrome 中进行了测试)。您可能会发现您实际上有两个请求:您期望的一个 - 加上 favicon.ico 的一个。而您的应用正在为这两者提供服务。