ASP.NET核心IIS 7.5中的WebAPI 500内部错误 [英] ASP.NET Core WebAPI 500 Internal error in IIS 7.5

查看:3814
本文介绍了ASP.NET核心IIS 7.5中的WebAPI 500内部错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我挣扎得到这个的WebAPI工作。好了,在IIS下工作。一切工作在IIS的前preSS很好,但是当我发布,特别是1 API请求不起作用。我试图访问的URL API / [控制器] / {日期} / {整数} 。我不断收到500服务器错误。我的另一条路线 API / [控制器] / {日期} 的作品。

下面是我的API控制器:

  [路线(API / [控制器])]
    公共类PostingsController:控制器
    {
        // GET:API /职位/ 5
        [HTTPGET({}日期)]
        公共字符串获取(串号)
        {
            归期;
        }        //获取API /职位/二分之二千〇一十六万〇四百〇七
        [HTTPGET({日期} / {} modeID)]
        公开名单< TruckPosting>获取(字符串日期,INT modeID)
        {
            TruckPosting TP =新TruckPosting();
            清单< TruckPosting> truckPostings = tp.GetTruckPostings(日期,modeID);
            返回truckPostings;
        }
    }

可能的原因是,我试图返回一个List<>?我难倒考虑它VS的IIS防爆preSS正常工作。

修改

下面是我的startup.cs页:

 公共无效ConfigureServices(IServiceCollection服务)
        {
            services.AddMvc();
        }公共无效Configure1(IApplicationBuilder应用程序,IHostingEnvironment ENV,ILoggerFactory的LoggerFactory)
            {
                app.UseIISPlatformHandler();
                app.UseDefaultFiles();
                app.UseStaticFiles();
                app.UseFileServer(真);
                app.UseMvc();
            }            //此方法被运行时调用。使用此方法来配置HTTP请求管道。
公共无效配置(IApplicationBuilder应用程序,IHostingEnvironment ENV,ILoggerFactory的LoggerFactory)
            {
                app.Map(/为approot(APP1)=> this.Configure1(APP1,ENV,的LoggerFactory));
            }


解决方案

这是一个很好的想法,这可能是事实,你返回一个列表。我们工作的核心Web API方法和他们都返回任务<&IEnumerable的LT;富>> 。尝试改变的返回类型列表< TruckPosting> 任务< IEnumerable的< TruckPosting>>

编辑:要查看详细信息500(内部服务器)的错误,你需要把code的下面一行在您的配置(或Configure1)的开头方法:

  app.UseDeveloperExceptionPage();

和显然这不是你想要的东西在生产环境中。

EDIT2:在VS运行,您可以用code以下,只要托管显示异常的详细信息:在属性的调试部分环境变量设置为发展。发布后,您将需要创建一个名为ASPNET_ENV系统环境变量并将其值设置为发展或code不会调用UseDeveloperExceptionPage()方法。

 如果(env.IsDevelopment())
{
    app.UseDeveloperExceptionPage();
}

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));
            }

解决方案

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();
}

这篇关于ASP.NET核心IIS 7.5中的WebAPI 500内部错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆