Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
177 views
in Technique[技术] by (71.8m points)

Default routing issue in ASP.Net Core 3.1 MVC

I have an ASP.Net Core 3.1 MVC project running at https://localhost:5006 using default routing.

            app.UseRouting();
            ...
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
                //endpoints.MapRazorPages();
            });

If I browse to https://localhost:5006/Home/Index or even https://localhost:5006/Home, it works as expected. (The Index action of the Home controller is executed.)

But when I browse to https://localhost:5006, I get a blank page in the browser.

Looking at the logs (pasted below), Routing.EndpointMiddleware (or any other middleware) seems to not be running on the request to '/' (like it is on the call to '/Home'. Any ideas of what to look at next to debug this?


Here is output from the Kestrel console:

First Request

info: Microsoft.AspNetCore.Hosting.Diagnostics[1] Request starting HTTP/2 GET https://localhost:5006/

info: Microsoft.AspNetCore.Hosting.Diagnostics[2] Request finished in 11.5922ms 200

Second Request

info: Microsoft.AspNetCore.Hosting.Diagnostics[1] Request starting HTTP/2 GET https://localhost:5006/home

info: Microsoft.AspNetCore.Authorization.DefaultAuthorizationService[1] Authorization was successful.

info: Microsoft.AspNetCore.Routing.EndpointMiddleware[0] Executing endpoint 'Project.Controllers.HomeController.Index (Project)'

info: Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker[3] Route matched with {action = "Index", controller = "Home"}. Executing controller action with signature System.Threading.Tasks.Task`1[Microsoft.AspNetCore.Mvc.IActionResult] Index(Project.Contracts.PageInfo, Project.Contracts.Query) on controller Project.Controllers.HomeController

...

question from:https://stackoverflow.com/questions/65947150/default-routing-issue-in-asp-net-core-3-1-mvc

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...