Skip to content

URL.Page returns null unexpectedly #6200

Closed
@gregoryagu

Description

@gregoryagu

This code returns null, instead of throwing an exception, when Area is used (Area/Identity...)

var callbackUrl = Url.Page(
                "/Account/ConfirmEmail",
                pageHandler: null,
                values: new { userId = userId, code = code },
                protocol: Request.Scheme);,

I ran into this and it was difficult to debug until I found this issue: aspnet/Mvc#8280

However, I think this is a bug, not a documentation issue as was concluded, because it the issue is hidden to the developer when it occurs.

In other words, to reproduce:

  1. New Aspnet Core project is created using Identity. Everything works as expected.

  2. Scaffolding of Identity is added, so that Identity is now under an Area.

But the generated page from the scaffolding includes:

var callbackUrl = Url.Page(
                "/Account/ConfirmEmail",
                pageHandler: null,
                values: new { userId = userId, code = code },
                protocol: Request.Scheme);,

instead of:

var callbackUrl = Url.Page(
                "/Account/ConfirmEmail",
                pageHandler: null,
                values: new { area="Identity", userId = userId, code = code },
                protocol: Request.Scheme);,

callbackUrl is now null, so the email that is generated now has a link that does not work, but no-one knows about it unless there is some testing of some sort or is reported by end user.

I don't know why it returns null, but it appears it is not finding the page, and so is returning null. Instead, it should thrown an exception, as there is never a case were you want the callbackURL to be null.

The other obvious point here is that the generated code should include the area so it works out of the box.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DoneThis issue has been fixedarea-identityIncludes: Identity and providersbugThis issue describes a behavior which is not expected - a bug.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions