Skip to content

Instantly share code, notes, and snippets.

@demofan
Created June 22, 2019 18:10
Show Gist options
  • Save demofan/d44c57f76f43495241af16bed4586aea to your computer and use it in GitHub Desktop.
Save demofan/d44c57f76f43495241af16bed4586aea to your computer and use it in GitHub Desktop.
Change RazorPage default page
public class DefaultPageRouteModelConvention : IPageRouteModelConvention
{
public void Apply(PageRouteModel model)
{
if (model.RelativePath == "/Pages/Index.cshtml")
{
var currentHomePage = model.Selectors.Single(s => s.AttributeRouteModel.Template == string.Empty);
model.Selectors.Remove(currentHomePage);
}
if (model.RelativePath == "/Pages/InputType.cshtml")
{
model.Selectors.Add(new SelectorModel()
{
AttributeRouteModel = new AttributeRouteModel
{
Template = string.Empty
}
});
}
}
}
services.AddMvc()
.AddRazorPagesOptions(options =>
{
options.Conventions.Add(new DefaultPageRouteModelConvention());
})
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment