Search code examples
c#.netauthenticationrazor-pages

In .NET authentication the application not confirmed the account because the code is null, why?


I am using .NET authentication, the application (Razor Pages) not confirmed the account because the code is null but it's exists in the link, why is that?

the code is null

code exists in the link i received

I deployed the database and the application for free hosting because I thought that's the reason but it's not.

& is not exist in 'callbackUrl'

& is exist in 'confirmCode'

i think the problem is here: var confirmCode = HtmlEncoder.Default.Encode(callbackUrl);


Solution

  • i think the problem is here: var confirmCode = HtmlEncoder.Default.Encode(callbackUrl);

    Yes, it is. HTML encoding is used for encoding HTML for display in a web page. It converts HTML characters to their entities (e.g. < becomes &lt; and & becomes &amp;) so that you don't embed actual HTML into your page.

    When encoding a URL, you should use the WebUtility.UrlEncode method instead: https://learn.microsoft.com/en-us/dotnet/api/system.net.webutility.urlencode?view=net-7.0, then URL-safe characters like & are not altered, and your query string is understood correctly by the model binder.