Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Core WebAPI 500 Internal error in IIS 7.5

I'm struggling to get this WebAPI to work. Well, work with IIS. Everything works fine in IIS express, but when I publish it, specifically 1 api request doesn't work. I'm trying to access a url of API/[Controller]/{date}/{integer}. I keep getting the 500 server error. My other route of API/[Controller]/{date} works.

Here's my API Controller:

[Route("api/[controller]")]
    public class PostingsController : Controller
    {
        // GET: api/Postings/5
        [HttpGet("{date}")]
        public string Get(string date)
        {
            return date;
        }

        // GET api/Postings/20160407/2
        [HttpGet("{date}/{modeID}")]
        public List<TruckPosting> Get(string date, int modeID)
        {
            TruckPosting tp = new TruckPosting();
            List<TruckPosting> truckPostings = tp.GetTruckPostings(date, modeID);
            return truckPostings;
        }
    }

Could the reason be that I'm trying to return a List<>? I'm stumped considering it works fine in VS's IIS Express.

Edit

Here's my startup.cs page:

public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
        }

public void Configure1(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
            {
                app.UseIISPlatformHandler();
                app.UseDefaultFiles();
                app.UseStaticFiles();
                app.UseFileServer(true);
                app.UseMvc();
            }

            // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
            {
                app.Map("/appRoot", (app1) => this.Configure1(app1, env, loggerFactory));
            }
like image 276
Brandon Avatar asked Apr 07 '16 17:04

Brandon


People also ask

How do I fix 500 Internal server error in IIS 7?

IIS error The error 500.19 is an internal server error often occurring on a server using Microsoft IIS software. It indicates that the configuration data for the page is invalid. To solve the issue, delete the malformed XML element from the Web. config file or from the ApplicationHost.

How does web API handle 500 internal server error?

If the error was caused by the backend server, go to Error in the Backend Server. Select the API request that is failing with 500 Internal Server Error in the trace. Examine the request and select the specific policy that has failed or the flow named "Error" that is immediately following the failed policy in the trace.

How do you fix 500 Internal server error There is a problem with the resource you are looking for and it Cannot be displayed?

There is a problem with the resource you are looking for, and it cannot be displayed. The first solution to a 500 internal server error is to refresh the page. If the error persists, you may try clearing the cookies, deactivating faulty plugins or themes, fixing the . htaccess file, or contacting your hosting provider.


1 Answers

That's a good thought that it might that fact that you're returning a List. We have working Core Web API methods and all of them return Task<IEnumerable<Foo>>. Try changing the return type List<TruckPosting> to Task<IEnumerable<TruckPosting>>

EDIT: To view the details for 500 (internal server) errors you will need to put the following line of code at the beginning of your Configure (or Configure1) method:

app.UseDeveloperExceptionPage();   

And obviously this is not something you want in a production environment.

EDIT2: When running in VS you can use the code below to show exception details as long as the Hosting:Environment variable in the Debug section of Properties is set to "Development". After publishing you will need to create a System Environment variable named ASPNET_ENV and set its value to "Development" or the code will not call the UseDeveloperExceptionPage() method.

if (env.IsDevelopment())
{
    app.UseDeveloperExceptionPage();
}
like image 188
Clint B Avatar answered Oct 24 '22 08:10

Clint B