2017-06-13 200 views
0

我是新来的Asp.net(.Net Core)Web API。 我做了AdminController,但当我请求的URL本地主机:52054/API /管理/得到我没有在提琴手上找到404。 这里是我的AdminController & Startup.cs AdminController ImageAsp.net WebApi .net核心请求返回404

namespace Api2017_1.Controllers 
{ 
    [Produces("application/json")] 
    [Route("api/Admin")] 
    public class AdminController : Controller 
    { 
     // GET: api/Admin 
     [HttpGet] 
     public async Task<BsonDocument> Get() 
     { 
      const string cs = "mongodb://localhost:27017"; 
      var client = new MongoClient(cs); 
      var db = client.GetDatabase("store"); 
      var coll = db.GetCollection<BsonDocument>("admins"); 
      using (var cursor = await coll.Find(new BsonDocument()).ToCursorAsync()) 
      { 
       while (await cursor.MoveNextAsync()) 
       { 
        foreach(var doc in cursor.Current) 
        { 
         return doc; 
        } 
       } 

      } 
      return (BsonDocument)0; 
     } 

Startup.cs Image

public class Startup 
{ 
    public Startup(IHostingEnvironment env) 
    { 
     var builder = new ConfigurationBuilder() 
      .SetBasePath(env.ContentRootPath) 
      .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) 
      .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) 
      .AddEnvironmentVariables(); 
     Configuration = builder.Build(); 
    } 

    public IConfigurationRoot Configuration { get; } 

    // This method gets called by the runtime. Use this method to add services to the container. 
    public void ConfigureServices(IServiceCollection services) 
    { 
     // Add framework services. 
     services.AddMvc(); 
    } 

    // 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) 
    { 
     loggerFactory.AddConsole(Configuration.GetSection("Logging")); 
     loggerFactory.AddDebug(); 

     app.UseMvc(); 
    } 
} 

任何人都可以指导我在哪儿出错了。 在此先感谢。

+0

代码是“文本”,而不是图像。将代码的“文本”放在问题中。 –

+1

@ nabish-khan:'试试localhost:52054/API/admin' url –

回答

0

您正在请求不正确的网址。使用localhost:52054/API/admin而不是请求类型为Get。