Mvc: URL.Page returns null

Created on 15 Aug 2018  路  3Comments  路  Source: aspnet/Mvc

Is this a Bug or Feature request?:

Bug

Steps to reproduce (preferably a link to a GitHub repo with a repro project):

Description of the problem:

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

The above code works without issues under Areas/Identity/Pages/Account/Manage/Index.cshtml.cs.

However when I try to run the same code in a different model, in a different directory such as Pages/Private/Home.cs, I find that it does not work. Reading documentation on this code does not give any clues why the above code will return null.

Version of Microsoft.AspNetCore.Mvc or Microsoft.AspNetCore.App or Microsoft.AspNetCore.All:

Microsoft.AspNetCore.Mvc (2.1)

investigate

Most helpful comment

@workmonitored - I expect that what's needed here is for you to add area to the route values:

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

The relevant section of the docs doesn't mention pages or the identity package, but explains some of the concepts. https://docs.microsoft.com/en-us/aspnet/core/mvc/controllers/areas?view=aspnetcore-2.1#link-generation

I've logged https://github.com/aspnet/Docs/issues/8291 to track cleaning up the docs. Let me know if this helps.

All 3 comments

Thanks for contacting us, @workmonitored.
In order for us to investigate this issue, please provide a minimalistic repro project that illustrates the problem.
@rynowak, can you please look at this? Thanks!

@workmonitored - I expect that what's needed here is for you to add area to the route values:

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

The relevant section of the docs doesn't mention pages or the identity package, but explains some of the concepts. https://docs.microsoft.com/en-us/aspnet/core/mvc/controllers/areas?view=aspnetcore-2.1#link-generation

I've logged https://github.com/aspnet/Docs/issues/8291 to track cleaning up the docs. Let me know if this helps.

Yes, that's correct. It explains some of the stuff but I was not sure, area was allowed or not. I have found it in other method calls but not for this. I am going ahead and closing it since that's all I needed.

Was this page helpful?
0 / 5 - 0 ratings