Tooling: IISPlatformHandler's Debug request reaches the users application

Created on 4 Nov 2015  路  21Comments  路  Source: aspnet/Tooling

If you have the following in your startup application:

C# app.Run(async (context) => { await context.Response.WriteAsync("Hello World!"); });

You'll see the middleware be invoked twice.

Most helpful comment

The debugger is sending a DEBUG request to make IIS Express launch the site so it can attach. A simple inline middleware at the top of your Startup.Configure method can filter it out:

app.Use((context, next) =>
{
  if (string.Equals(context.Request.Method, "DEBUG"))
  {
    return Task.FromResult(0);
  }
  return next();
});

All 21 comments

Hmm why is this a tooling bug?

Tooling is the one performing two requests :smile:.

  1. The normal page request when hitting F5
  2. An extra DEBUG request to kick start DNX and attach.

I don't think tooling will stop sending the DEBUG request - it has to do that. Is the bug that the request makes it past some DNX/Hosting thing?

From talks with @BillHiebert it sounded like tooling could write a nativish module to eat the request.

Ah ok...

Is there any action needed here? I think @BillHiebert may have already fixed this but not totally sure.

I think the fix would need to occur in middleware. I don't see how tooling can fix this as we need to send a request to get the httpPlatformHandler to start dnx.exe.

@davidfowl @Tratcher any thoughts on this? Can/should we block the DEBUG request from VS at some early layer? I think this might be what's happening here: https://github.com/aspnet/Mvc/issues/3585

This would be easy for the UseIISPlatformHandler middleware to eat.

@Tratcher Is it possible to do it earlier? This problem occurs with any server as long as you start it with debugging.

It's possible, but I don't recommend it. This is specific to IIS/Express and VS. UseIISPlatformHandler is the second item in our templates after the debugging tools: https://github.com/aspnet/Templates/blob/dev/src/BaseTemplates/StarterWeb/Startup.cs#L49

Still dependent on where you put it though :/

UseIISPlatformHandler has to be super early to work at all.

Is there any tooling work pending here?

Yes, but we've clearly never closed on the design.

Because of this "double start", I get an EF error on the second start because it says that EF is in the state of initializing. So either I need a way to initial EF in Startup (which I don't think is a good idea, but still learning EF) or as way to only keep HomeController from being called just once.

So far, I have not found a solution. Since this occurs only in debug mode, then obviously a MS ASP.NET5 or MVC6 issue in what it starts.

It's still in RC2. So how can I detect it and not start off expensive external tasks two times in parallel? They sometimes end up colliding and all falls apart before it has begun. Very frustrating. Why is anybody doing two requests at all? I don't see any reason in that. After starting the debugging, my web browser opens the first URL. No other instance should request anything from the web application.

The debugger is sending a DEBUG request to make IIS Express launch the site so it can attach. A simple inline middleware at the top of your Startup.Configure method can filter it out:

app.Use((context, next) =>
{
  if (string.Equals(context.Request.Method, "DEBUG"))
  {
    return Task.FromResult(0);
  }
  return next();
});

Yep, that code fixes to issue. Thanks!

Does that mean we'll all have to insert this code to fix a debugger annoyance with the framework? I'm waiting for the first NuGet package to arise that does it. :-p

Was this page helpful?
0 / 5 - 0 ratings