Search code examples
c#asp.net-coreasp.net-core-2.2

Cannot call my custom razor page (HTTP 404)


I created a new ASP.NET Core MVC application from scratch with authentication by "storing user accounts in-app". I extended ASP Identity with my own custom VerifyEmail.cshtml razor page.

This looks quite good, doesn't it?

Custom razor page inside Manage folder

But I cannot request https://localhost:44345/Identity/Account/Manage/VerifyEmail, it got 404!

What did I forget?

Here's the VerifyEmail.cshtml:

@model VerifyEmailModel
@{
    ViewData["Title"] = "Verify Email";
    ViewData["ActivePage"] = ManageNavPages.VerifyEmail;
}
<h4>@ViewData["Title"]</h4>
<partial name="_StatusMessage" for="StatusMessage" />
<div class="row">
    <div class="col-md-6">
        <form method="post">
            <div class="form-group">
                <label asp-for="Email"></label>
                <input asp-for="Email" class="form-control" disabled="disabled" />
            </div>
            <button id="email-verification" type="submit" class="btn btn-secondary">Send verification email</button>
        </form>
    </div>
</div>

Solution

  • Add @page on your first line of VerifyEmail.cshtml :

    @page
    @model VerifyEmailModel
    

    @page makes the file into an MVC action - which means that it handles requests directly, without going through a controller. @page must be the first Razor directive on a page. @page affects the behavior of other Razor constructs.