c# - ASP.NET Core“找不到此本地主机页面”
问题描述
尝试测试我的应用程序时,我使用 vs2017 得到“找不到此本地主机页面”。
尝试访问https://localhost:44347/test/test
这是我的 Startup.cs
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseMvc();
}
}
解决方案
根据您共享的代码,您需要使用属性路由显式提供路由。
public class ProjectenEnPersoneelCONTROLLER : Controller
{
[Route("Test/Test")]
public IActionResult Index()
{
var webClient = new WebClient();
var json = webClient.DownloadString(@"D:\Users\tijnv\source\repos\API_STA_1\API_STA_1\Json\test-request.json");
var projects = JsonConvert.DeserializeObject<Projects>(json);
return View(projects);
}
}
或者,您可以将控制器重命名为 TestController 并将 Action 方法重命名为 Test
public class TestController : Controller
{
public IActionResult Test()
{
var webClient = new WebClient();
var json = webClient.DownloadString(@"D:\Users\tijnv\source\repos\API_STA_1\API_STA_1\Json\test-request.json");
var projects = JsonConvert.DeserializeObject<Projects>(json);
return View(projects);
}
}
推荐阅读
- angular - 我的图像以数字形式出现
- numpy - 如何计算 np.insert "obj" 参数?
- docker - 在 jenkins slave 上运行 docker build 时出错
- android - NativeScript Vue + Fastlane - 自定义 iOS/Android 项目路径?
- javascript - 如何使用css和js创建被动波浪效果按钮
- vue.js - Vue.js 在 ajax 请求期间禁用组件
- python - pythreejs 无法在 jupyter notebook 中渲染大网格(但成功渲染了小网格)
- angular - 重新加载页面时,从 Angular 6 中的 url 中删除 # 后页面未加载。
- javascript - 保存AngularJS后如何在页面上显示新数据
- nginx - 如何显示来自 Gryphon nginx 的多个 rtmp 流?