Created
May 28, 2021 20:59
-
-
Save manoj-choudhari-git/69e8bf2c44ffe3ab9bfba0c11eb0fa46 to your computer and use it in GitHub Desktop.
.NET Core MVC application demo - Setting up conventional routing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Startup | |
{ | |
public void ConfigureServices(IServiceCollection services) | |
{ | |
// Initialize route information | |
services.AddControllersWithViews(); | |
} | |
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) | |
{ | |
app.UseRouting(); | |
app.UseEndpoints(endpoints => | |
{ | |
// same as example shown below | |
// endpoints.MapDefaultControllerRoute(); | |
// Below is same as what MapDefaultControllerRoute does | |
endpoints.MapControllerRoute( | |
name: "default", | |
pattern: "{controller=Home}/{action=Index}/{id?}"); | |
// This is called as dedicated conventional routing | |
// as action is fixed | |
endpoints.MapControllerRoute( | |
name: "default", | |
pattern: "blog/{*article}", | |
defaults: new { controller = "Blog", action = "GetBlogPost" }); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment