Created
June 22, 2019 18:10
-
-
Save demofan/d44c57f76f43495241af16bed4586aea to your computer and use it in GitHub Desktop.
Change RazorPage default page
This file contains hidden or 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 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 | |
} | |
}); | |
} | |
} | |
} |
This file contains hidden or 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
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