【发布时间】:2016-04-07 17:47:41
【问题描述】:
我正在努力让这个 WebAPI 工作。好吧,使用 IIS。在 IIS express 中一切正常,但是当我发布它时,特别是 1 个 api 请求不起作用。我正在尝试访问API/[Controller]/{date}/{integer} 的网址。我不断收到 500 服务器错误。我的API/[Controller]/{date} 的另一条路线有效。
这是我的 API 控制器:
[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;
}
}
原因可能是我试图返回一个列表?考虑到它在 VS 的 IIS Express 中运行良好,我很难过。
编辑
这是我的 startup.cs 页面:
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));
}
【问题讨论】:
-
你检查了服务器的事件日志吗?通常 500 是由异常引起的,通常您可以在 IIS 机器上的
Application Log中找到这些详细信息。 -
你可以调查一下你的字符串日期参数的使用
-
@Infer-On 你是什么意思?
-
@CodingGorilla 日志没有任何特别的内容。只是一些时间空闲日志和一些 404。语法是否正确?例如我可以传入一个字符串参数,然后是一个整数吗? ({date} 是字符串,{modeID} 是 int)
-
现在,我还没有在我的 startup.cs 文件中进行任何 WebAPI 映射。我已经为应用程序本身做了 1 次映射。
标签: c# asp.net iis asp.net-web-api asp.net-mvc-5