ASP.NET Core WebAPI 500 Internal Error in IIS 7.5

I am trying to get this webapi to work. Well, work with IIS. Everything works fine in IIS express, but when I publish it, in particular, 1 api request does not work. I am trying to access the API/[Controller]/{date}/{integer} URL API/[Controller]/{date}/{integer} . I keep getting server 500 error. My other API/[Controller]/{date} route API/[Controller]/{date} works.

Here is 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; } } 

Maybe the reason is that I'm trying to return List <>? I'm at a dead end considering it works great in VS IIS Express.

Edit

Here is 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)); } 
+5
source share
2 answers

It is a good idea that this may mean that you are returning a list. We have Core Web API methods, and all of them return Task<IEnumerable<Foo>> . Try changing the return type of List<TruckPosting> to Task<IEnumerable<TruckPosting>>

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

 app.UseDeveloperExceptionPage(); 

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

EDIT2: when starting up in VS, you can use the code below to show the details of the exception if the Hosting: Environment parameter in the Debug section of the 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", otherwise the code is not called by the UseDeveloperExceptionPage () method.

 if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } 
+8
source

I posted the ASP.NET Core custom exception handler on GitHub today. I thought this might be useful for you, since you are creating a SPA and probably calling a lot of Web API methods.

This is a middleware project that returns error messages for web API calls and redirects to the error page for non-web API calls. It can also log exceptions in the SQL Server database. This is done in a separate thread to aid in performance.

The solution includes a demo application that shows how to use the exception handler for both web API exceptions and non-Web API exceptions.

Here is the link.
https://github.com/ClintBailiff/CustomExceptionHandler

If you finish the check and offer any suggestions or comments, I like to listen to them.

0
source

Source: https://habr.com/ru/post/1246497/


All Articles