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;
}
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();
}
}
任何人都可以指導我在哪兒出錯了。 在此先感謝。
代碼是「文本」,而不是圖像。將代碼的「文本」放在問題中。 –
@ nabish-khan:'試試localhost:52054/API/admin' url –