我想将我的框架移植到新的 .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 的请求。而您的应用正在为这两者提供服务。
关于c# - 为什么 DNX 运行代码两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35639858/