【问题标题】:My razor pages are not working all of the generate the same error : Localhost page cant be found我的剃须刀页面无法正常工作所有生成相同的错误:找不到本地主机页面
【发布时间】:2021-04-10 13:11:52
【问题描述】:

This is my startup.cs file

有谁知道出了什么问题This is my index.cshtml

好的,所以我的代码将位于其非常基本的 startup.cs 文件和 index.cshtml 文件的下方,其中包含一些仅用于测试的基本代码

      public class Startup
{
    // This method gets called by the runtime. Use this method to add services to the container.
    // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddRazorPages();
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseExceptionHandler("/Error");
            app.UseHsts();
        }


        app.UseStaticFiles();
        app.UseRouting();

        

        app.UseEndpoints(endpoints =>
         {
          endpoints.MapRazorPages();
         });


    }
}}
@page

@DateTime.Now

【问题讨论】:

  • 请将代码和数据添加为文本 (using code formatting),而不是图像。图片:A)不允许我们复制粘贴代码/错误/数据进行测试; B) 不允许根据代码/错误/数据内容进行搜索;和many more reasons。除了代码格式的文本之外,只有在图像添加了一些重要的东西,而不仅仅是文本代码/错误/数据传达的内容时,才应该使用图像。
  • 对不起,我是新手,现在已将其添加为代码
  • 有什么相关性吗? stackoverflow.com/questions/43468715/…
  • 请显示页面背后的代码

标签: asp.net-core asp.net-web-api razor


【解决方案1】:

尝试新建一个项目,看看是否有同样的问题。

您是否在服务方面应用了一些东西?你可以分享它。

或者你可以先试试这些代码:

配置服务:

services.AddMvc(options =>
        {
            options.EnableEndpointRouting = false;
        });

配置:

app.UseMvcWithDefaultRoute();

【讨论】:

    猜你喜欢
    • 2020-11-20
    • 1970-01-01
    • 2021-05-31
    • 2019-09-13
    • 2021-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-19
    相关资源
    最近更新 更多