【发布时间】:2017-09-28 17:11:30
【问题描述】:
我刚刚开始使用 Asp.net core api 和 Aurelia
我通常使用Laravel。
我已经安装了所有东西 + aurelia 路由器。现在我想对我的 asp.net 核心 api 进行 api 调用,但我没有看到 json 结果?
示例控制器如下所示:
public class ValuesController : Controller
{
// GET api/values
[HttpGet]
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
}
但是当我使用 google chrome http://localhost:9001/api/values 发出获取请求时,我只看到一个空白的白页?我应该如何联系我的api?
编辑
Startup.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace Forum
{
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.UseDefaultFiles();
app.UseStaticFiles();
app.UseMvc();
}
}
}
【问题讨论】:
-
您使用 google chrome 发出的请求的 HTTP 响应状态如何?
-
请分享您的 Startup.cs 课程
-
我没有看到状态码。 @S.Petrosov 请看我的编辑。
-
@Jamie 在任何浏览器开发工具窗口中按 F12 将打开转到网络并找到您的请求会有响应代码,例如像这样 take.ms/CtlcH
-
@S.Petrosov 谢谢我看到了这个:s9.postimg.org/l1stfedhr/…
标签: c# asp.net-mvc asp.net-core aurelia