加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – Web api界面在本地工作,但不在Azure上

发布时间:2020-12-16 00:25:23 所属栏目:asp.Net 来源:网络整理
导读:我的情况与 this question非常相似,但由于他没有得到答案,我以为我会投入更多的投入。 一切都在本地工作(在VS嵌入式服务器上)。当我部署到Azure时,我收到一个404错误,伴随着“没有找到与控制器名称匹配的类型”。 然而,当我加载routedebugger模块时,即
我的情况与 this question非常相似,但由于他没有得到答案,我以为我会投入更多的投入。

一切都在本地工作(在VS嵌入式服务器上)。当我部署到Azure时,我收到一个404错误,伴随着“没有找到与控制器名称匹配的类型”。

然而,当我加载routedebugger模块时,即使在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;
        }
    }
}

解决方法

切换路线的顺序,然后重试。
GlobalConfiguration.Configuration.Routes.MapHttpRoute(
            name: "ActionApi",defaults: new { id = RouteParameter.Optional }
        );
        GlobalConfiguration.Configuration.Routes.MapHttpRoute(
            name: "DefaultApi",defaults: new { id = RouteParameter.Optional }
        };

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读