0

I have the below route mapped in my AreaRegistration:

public override void RegisterArea(AreaRegistrationContext context)
    {
        if (context != null)
        {
            context.Routes.MapHttpRoute(
                name: "API_Default",
                routeTemplate: "Areas/Test/AIO/api/{controller}/{id}",
                defaults: new
                {
                    id = RouteParameter.Optional
                });

When I look at the Global.asax file, I can see the HttpRoute is being Registered, and is listed in the RouteTable.Routes as a {System.Web.Http.WebHost.Routing.HttpWebRoute}.

Problem is, when I go to the url... https://myRoot/Areas/Test/AIO/api/AioApi/test or https://myRoot/Areas/Test/AIO/api/AioApi, it's giving me a 500 internal server error.

I'm not sure how to view the actual error, when stepping thru the code I cannot see anything after it leaves Application_BeginRequest.

My controller code:

public class AioApiController : ApiController
{
    // GET api/<controller>
    public IEnumerable<string> Get()
    {
        return new string[] { "value1", "value2" };
    }

Any insight as to why I cannot hit the API controller? I can hit my regular MVC controller in the same context.

Any help is greatly appreciated!

4

1 回答 1

0

我在 WebApi 中发现的一件事是有两个 Route 集合:System.Web.Routing.RouteCollectionSystem.Web.Http.HttpRouteCollection. 我相信(但不记得)您需要使用后者才能使您的ApiController派生正常工作(幸运的是语法相同)。

于 2012-08-14T10:32:13.947 回答