Skip to content

Instantly share code, notes, and snippets.

@manoj-choudhari-git
Created May 28, 2021 20:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manoj-choudhari-git/69e8bf2c44ffe3ab9bfba0c11eb0fa46 to your computer and use it in GitHub Desktop.
Save manoj-choudhari-git/69e8bf2c44ffe3ab9bfba0c11eb0fa46 to your computer and use it in GitHub Desktop.
.NET Core MVC application demo - Setting up conventional routing
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