Home > Enterprise >  asp.net relative path IdentityHelper.GetUserConfirmationRedirectUrl
asp.net relative path IdentityHelper.GetUserConfirmationRedirectUrl

Time:01-31

I am running into some issues with relative paths when deploying my website. This is an ASP.Net webform project The site running without issues on the local machine, with links pointing as they should.

I deployed the site to subfolder (not the IIS root) and made that folder an application. currently my site is deployed to http://www.example.com/foo/ The first issue i noted was that links like /Account/Register.aspx would on my local machine point to https://localhost:44337/Account/Register but on the deployed site it would point to http://www.example.com/Account/Register.aspx instead of the correct path http://www.example.com/foo/Account/Register.aspx. That was relatively easily fixable by changing the links from /Account/Register.aspx to ~/Account/Register.aspx.
A more difficult issue was dealing with an email confirmation link generated through the code below:

string code = manager.GenerateEmailConfirmationToken(user.Id);
string callbackUrl = IdentityHelper.GetUserConfirmationRedirectUrl(code, user.Id, Request);
manager.SendEmail(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\""   callbackUrl   "\">here</a>.");

On my local machine, the link points (correctly).

https://localhost:44337:80/Account/Confirm?code=blablabla

On the web deployed app, the link points to

http://www.example.com:80/Account/Confirm?code=blablabla

Physical path

E:\web\mysite\htdocs\Account\Confirm

The correct one should have been

http://www.example.com:80/foo/Account/Confirm?code=blablabla

Could anyone please suggest how to deal with this problem with relative links overall or specifically how to get IdentityHelper.GetUserConfirmationRedirectUrl to generate the link with the right relative path? Much appreciated.

CodePudding user response:

The answer was simply to adjust the url path in GetUserConfirmationRedirectUrl in identitymodules.cs

  • Related