在mvc asp.net的浏览器中找不到API控制器

时间:2016-04-11 07:36:17

标签: c# asp.net-mvc asp.net-web-api

我是single page application中的新人。我在这里创建webapi

using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.Description;
using WebApplication6.Models;

namespace WebApplication6.Controllers
{
    public class ManageStudentInforAPIController : ApiController
    {
        private SchoolManagementEntities db = new SchoolManagementEntities();

        // GET: api/ManageStudentsInfoAPI  
        public IQueryable<Student> Get()
        {
            return db.Students;
        }
    }
}

但是当我调用此网址http://localhost:5411/ManageStudentInforAPI时,结果是

The resource cannot be found.

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly. 

Requested URL: /ManageStudentInforAPI

我的问题在哪里。你需要的任何细节我都可以发帖。我正在使用vs2015

enter image description here

1 个答案:

答案 0 :(得分:2)

api之前你错过了ManageStudentInforAPI。尝试按http://localhost:5411/api/ManageStudentInforAPI

替换您的网址

或者您可以将[Route("route")]添加到控制器或方法中,然后拨打http://localhost:5411/api/route