newly learning razor
app.MapGet("/", () => Results.Redirect("/Index"));
redirectings to page Index in Pages Folder. web browser address bar seems with route name like this:
http://localhost:5013/Index
is there a way to redirect to Index Page withot seeing Route Name? something like:
http://localhost:5013
newly learning razor
app.MapGet("/", () => Results.Redirect("/Index"));
redirectings to page Index in Pages Folder. web browser address bar seems with route name like this:
http://localhost:5013/Index
is there a way to redirect to Index Page withot seeing Route Name? something like:
http://localhost:5013
Share
Improve this question
edited yesterday
Brando Zhang
28.1k6 gold badges41 silver badges69 bronze badges
asked Feb 7 at 9:50
Fables AliveFables Alive
2,8101 gold badge34 silver badges48 bronze badges
3
|
1 Answer
Reset to default 2Actually, this is related with how you set the route for your page.
For example, if you set the route as below inside the index page, then the default page for the / is the index. There is no need to use mapget again.
@page "/"
@model IndexModel
@{
ViewData["Title"] = "Home page";
}
<div class="text-center">
<h1 class="display-4">Welcome</h1>
<p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
</div>
Also if you want to set some custom route for specific page, you could use AddPageRoute method directly inside the page options.
builder.Services.AddRazorPages().AddRazorPagesOptions(options => {
options.Conventions.AddPageRoute("/Index", "/test");
});
/
to/
? That will cause an infinite loop and therefore a Too Many Redirects error in the browser. FYIhttp://localhost:5013
andhttp://localhost:5013/Index
both point to the same page in your app. – Mike Brind Commented Feb 7 at 11:16