Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploying dotnetcore 5 web api to iis gives 404

I have an Web API project with .NET 5 (created directly from the template of visual studio Asp.NET Core Web API), it works just fine when debugging from Visual studio, tried to deploy it to IIS server, which has the Hosting Bundle of .NET 5 installed, the deployment apparently runs fine, but when I enter the url I have a 404. Have a separate MVC .NET 5 project, which I deploy in the same way and it runs perfectly fine.

Would like to know if someone can point me to the right direction, can't find what I'm missing here.

like image 231
Starlin González Avatar asked Dec 09 '20 13:12

Starlin González


2 Answers

After searching and messing with Startup.cs file I notice that

    app.UseSwagger();
    app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "api v1"));

Was inside the validation if(env.IsDevelopment()), but the api endpoints were working just fine, just that though that it doesn't work because I was unable to see the Swagger site, probably because you don't want to expose your api to everyone... feels like I miss a little explanation somewhere but all good now.

like image 68
Starlin González Avatar answered Oct 17 '22 07:10

Starlin González


Faced the same issue. After configuring, when tried to browse 404 error came up.

The reason is, Swagger page will be configured in only for development environment as below(in Startup.cs).

 if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseSwagger();
                app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "AppName v1"));
        }

The APIs will be available if we type in the correct url. If you still wants to view the Swagger file

  • Either change the code in startup.cs remove the check for

    if (env.IsDevelopment())

  • Or In your web.config file set environment as Development.

like image 42
Ajith Avatar answered Oct 17 '22 07:10

Ajith