dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.35k stars 9.99k forks source link

Can't debug ASP.NET Core 3.1 using IIS Express. Always yields HTTP 404. #25129

Closed vsfeedback closed 3 years ago

vsfeedback commented 4 years ago

This issue has been moved from a ticket on Developer Community.


I don't seem to be able to debug my ASP.NET Core Web API using IIS Express.

I'm always getting a 404 File not found response when using IIS Express configuration.

When I use Kestrel for debugging, everything works fine.

! [Kestrel / IIS Express results] (https://i.stack.imgur.com/1nZV1.png)

(Corresponding discussion can be found here.)

I zipped and added my Visual Studio 2019 solution to this case, so you can reproduce the issue for yourself.

Steps to reproduce:

  1. Unzip VS 2019 solution attached and open in Visual Studio 2019.
  2. Select "WebAPI" as start project.
  3. Select "IIS Express" configuration for debugging.
  4. Launch debugger.

Result: No matter which URL you enter, it always returns a 404 File not found.

Now ...

  1. Stop debugging.
  2. Select "WebAPI" configuration for debugging.
  3. Launch debugger.

Result: Everything works as expected.


Original Comments

Feedback Bot on 8/17/2020, 07:12 PM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.


Original Solutions

(no solutions)

SetTrend commented 4 years ago

Just to get the formatting and the images right:


Here's the repository to be able to reproduce the issue

I don't seem to be able to debug my ASP.NET Core Web API using IIS Express.

I'm always getting a 404 File not found response.

When I use Kestrel for debugging, everything works fine.

Why isn't IIS Express working?

This is my launchSettings.json file:

{
    "iisSettings":
    {
        "windowsAuthentication": false,
        "anonymousAuthentication": true,
        "iisExpress":
        {
            "applicationUrl": "http://localhost:52772/Users",
            "sslPort": 0
        }
    },
    "$schema": "http://json.schemastore.org/launchsettings.json",
    "profiles":
    {
        "IIS Express":
        {
            "commandName": "IISExpress",
            "launchBrowser": true,
            "environmentVariables":
            {
                "ASPNETCORE_ENVIRONMENT": "Development"
            }
        },
        "WebAPI":
        {
            "commandName": "Project",
            "launchBrowser": true,
            "environmentVariables":
            {
                "ASPNETCORE_ENVIRONMENT": "Development"
            },
            "applicationUrl": "http://localhost:5000"
        }
    }
}

Here's a screenshot depicting both situations: Kestrel on the left and IIS Express on the right:

enter image description here

Please note the HTTP status codes returned.

public static void Main(string[] args) =>
  Host
    .CreateDefaultBuilder(args)
    .ConfigureWebHostDefaults(webBuilder => webBuilder.UseStartup<WebConfiguration>())
    .Build()
    .Run();
public class WebConfiguration
{
  private readonly IConfiguration _configuration;

  public WebConfiguration(IConfiguration configuration) => _configuration = configuration;

  // This method gets called by the runtime once. Use this method to add services to the container for dependency injection.
  public void ConfigureServices(IServiceCollection services)
  {
    services
      .AddSingleton(_configuration.GetSection("AppSettings").Get<Options>())
      .AddScoped(typeof(IUserAccess), typeof(UserAccess))
      .AddScoped(typeof(ITaskItemAccess), typeof(TaskItemAccess))
      .AddScoped(typeof(IGenderAccess), typeof(GenderAccess))

      .AddSwaggerGen()

      .AddControllers()
      ;
  }

  // This method gets called by the runtime once. Use this method to configure the HTTP request pipeline.
  public void Configure(IApplicationBuilder app, IWebHostEnvironment env, Options options)
  {
    if (env.IsDevelopment()) app.UseDeveloperExceptionPage();

    app
      .UseHttpsRedirection()
      .UseRouting()
      .UseAuthorization()
      .UseEndpoints(endpoints => endpoints.MapControllers())
      .UseSwagger()
      ;

    if (env.IsDevelopment()) app.UseSwaggerUI();
  }
}
namespace WebAPI.Controllers
{
  [Route("[controller]")]
  [ApiController]
  public class UsersController : ControllerBase
  {
    private readonly IUserAccess _repository;

    public UsersController(IUserAccess repository) => _repository = repository;

    [HttpGet]
    public ICollection<User> Get() => _repository.Get();

...
Pilchie commented 4 years ago

@vijayrkn - any ideas here?

vijayrkn commented 4 years ago

@SetTrend - Thanks for the repro project. Just tried running the app on IISExpress first and it worked but then running on Ketrel gave the 404 error.

image

So this issue doesn't seem to be specific to IISExpress but the HttpsRedirection in startup not pointing to the right port.

@BillHiebert & @Tratcher - In case they know why the redirection fails.

Tratcher commented 4 years ago

@vijayrkn https redirection shouldn't be related, IIS isn't configured for https either in the launchsettings.json. Did you change the launch settings?

Tratcher commented 4 years ago

Oh, I see. That launchsettings gives the servers different paths, http://localhost:52772/Users vs http://localhost:5000. Why is it set up that way?

SetTrend commented 4 years ago

@Tratcher: Sorry, I misunderstood your question: I had been fiddling around with paths to see if there's any change. Unfortunately, that didn't work out. The different paths don't make a difference.

ghost commented 3 years ago

Thank you for contacting us. Due to a lack of activity on this discussion issue we're closing it in an effort to keep our backlog clean. If you believe there is a concern related to the ASP.NET Core framework, which hasn't been addressed yet, please file a new issue.

This issue will be locked after 30 more days of inactivity. If you still wish to discuss this subject after then, please create a new issue!