简体   繁体   English

Microsoft.AspNetCore.Routing.RouteCreationException: '创建名为'default' 和模板的路由时出错

[英]Microsoft.AspNetCore.Routing.RouteCreationException: 'An error occurred while creating the route with name 'default' and template

I am a newbie to the Asp.Net core, and I am just creating a new Asp.Net Core 2 application, but getting as error as preceding.我是 Asp.Net 核心的新手,我只是在创建一个新的 Asp.Net Core 2 应用程序,但得到了和前面一样的错误。

Microsoft.AspNetCore.Routing.RouteCreationException: 'An error occurred while creating the route with name 'default' and template '{controller=Home}/{action=Index}/{id=?}'.' Microsoft.AspNetCore.Routing.RouteCreationException:“创建名称为“default”且模板为“{controller=Home}/{action=Index}/{id=?}”的路由时出错。”

Below is my Configure function code.下面是我的Configure功能代码。

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}"
                    );
            });

            app.Run(async (context) =>
            {
                await context.Response.WriteAsync("Hello World!");
            });
        }

The screenshot of the error is given below.下面给出了错误的屏幕截图。

在此处输入图片说明

Can anyone please help me resolve this issue?任何人都可以帮我解决这个问题吗?

Huh, it was my mistake.呵呵,是我的错。 I added an extra character {id=?} in the template, instead of {id?} .我在模板中添加了一个额外的字符{id=?} ,而不是{id?} So my working code is looking as preceding.所以我的工作代码看起来和前面一样。

app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}"
                    );
            });

I read this information from here , just sharing as it may help someone.我从这里阅读了这些信息,只是分享,因为它可能对某人有所帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 创建路由时出错 - An error occurred while creating a route RouteCreationException:属性路由信息发生以下错误 - RouteCreationException: The following errors occurred with attribute routing information Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingProvider[48] 读取密钥环时出错 - Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingProvider[48] An error occurred while reading the key ring Microsoft.EntityFrameworkCore.DbUpdateException:'保存实体更改时出错。 SqlException:列名“UsersUserID”无效 - Microsoft.EntityFrameworkCore.DbUpdateException: 'An error occurred while saving the entity changes. SqlException: Invalid column name 'UsersUserID' C# Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1] 执行请求时发生未处理的异常 - C# Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1] An unhandled exception has occurred while executing the request aspnetcore 路由到 controller 操作与自定义路由 - aspnetcore routing to controller action with custom route 在AspNetCore.Mvc控制器中撰写路由模板 - Compose route template in AspNetCore.Mvc controller 创建PrintServer对象时发生异常。 Win32错误:打印机名称无效 - Exception occurred while creating the PrintServer object. Win32 error: The printer name is invalid 检索“ Microsoft.CSharp.4.3.0”的程序包元数据时发生错误 - An error occurred while retrieving package metadata for 'Microsoft.CSharp.4.3.0' 具有默认路由的属性路由 - Attribute Routing with Default Route
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM