首页 > 解决方案 > 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();
    }
}

标签: c#asp.netasp.net-core

解决方案


根据您共享的代码,您需要使用属性路由显式提供路由。

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);
    }
}

推荐阅读