Asp.net Web api接口在本地工作,但在Azure上不工作

Asp.net Web api接口在本地工作,但在Azure上不工作,asp.net,azure,asp.net-web-api-routing,Asp.net,Azure,Asp.net Web Api Routing,我的情况与他非常相似,但由于他没有得到答案,我想我应该多提供一些信息 在本地(VS嵌入式服务器上)一切正常。当我部署到Azure时,会出现一个404错误,并伴有“找不到与名为…”的控制器匹配的类型” 然而,当我加载模块时,即使在Azure上,映射也似乎正常 如何调试该问题 谢谢 亚历克斯 编辑:我的路线是这样创建的: GlobalConfiguration.Configuration.Routes.MapHttpRoute( name: "

我的情况与他非常相似,但由于他没有得到答案,我想我应该多提供一些信息

在本地(VS嵌入式服务器上)一切正常。当我部署到Azure时,会出现一个404错误,并伴有“找不到与名为…”的控制器匹配的类型”

然而,当我加载模块时,即使在Azure上,映射也似乎正常

如何调试该问题

谢谢

亚历克斯

编辑:我的路线是这样创建的:

            GlobalConfiguration.Configuration.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            };
            GlobalConfiguration.Configuration.Routes.MapHttpRoute(
                name: "ActionApi",
                routeTemplate: "api/{controller}/{action}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );
编辑2:这里是我的控制器类

    public class EmployeeController : ApiController
{
    // GET api/<controller>
    public IEnumerable<Employee> Get()
    {
        using (var context = new nws())
        {
            return context.Employees;
        }
    }

    // GET api/<controller>/5
    public Employee Get(int id)
    {
        using (var context = new nws())
        {
            return context.Employees.FirstOrDefault(e => e.ID == id);
        }
    }

    // GET api/<controller>/getbyatid/5
    public Employee GetByAtId(string id)
    {
        using (var context = new nws())
        {
            return context.Employees.FirstOrDefault(e => e.AtUserID == id);
        }
    }

    // POST api/<controller>
    public void Post([FromBody]string value)
    {
    }

    // PUT api/<controller>/5
    public void Put(int id, [FromBody]string value)
    {
    }

    // DELETE api/<controller>/5
    public void Delete(int id)
    {
    }

    // GET api/<controller>/timebank/5
    public int? GetTimeBank(string id)
    {
        using (var context = new nws())
        {
            var employee = context.Employees.FirstOrDefault(e => e.AtUserID == id);
            if (employee != null)
                return employee.GetTimeBank();
            return null;
        }
    }
}
公共类EmployeeController:ApicController
{
//获取api/
公共IEnumerable Get()
{
使用(var context=new nws())
{
返回上下文。员工;
}
}
//获取api//5
公共雇员获取(int id)
{
使用(var context=new nws())
{
返回context.Employees.FirstOrDefault(e=>e.ID==ID);
}
}
//获取api//getbyatid/5
公共雇员GetByAtId(字符串id)
{
使用(var context=new nws())
{
返回context.Employees.FirstOrDefault(e=>e.AtUserID==id);
}
}
//后api/
公共作废帖子([FromBody]字符串值)
{
}
//放置api//5
公共void Put(int id,[FromBody]字符串值)
{
}
//删除api//5
公共无效删除(int-id)
{
}
//获取api//timebank/5
public int?GetTimeBank(字符串id)
{
使用(var context=new nws())
{
var employee=context.Employees.FirstOrDefault(e=>e.AtUserID==id);
if(employee!=null)
return employee.GetTimeBank();
返回null;
}
}
}

切换路由顺序,然后重试

        GlobalConfiguration.Configuration.Routes.MapHttpRoute(
            name: "ActionApi",
            routeTemplate: "api/{controller}/{action}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );
        GlobalConfiguration.Configuration.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        };

您是否使用任何IoC容器来解析控制器?不,控制器是一个标准类,我在应用程序中创建路由。\u开始使用上面编辑中的代码。与链接到的问题相同:MVC是否有可能未正确部署到Azure?您能否提供您的工作本地url,您试图在azure上访问的url,并告诉我们您是如何部署到azure的。它是一个网站,网络角色,虚拟机。。。谢谢Salexbilo,如果我没记错的话,你是在自我托管你的web api。如果是这样的话,我注意到这一页上有这样一条注释:“如果您自托管Web API,那么必须直接在HttpSelfHostConfiguration对象上设置路由表。”