Home > Mobile >  How to stop area from automatically being added to the URL when using Url.Action?
How to stop area from automatically being added to the URL when using Url.Action?

Time:03-03

The controller that calls this method is in Areas/AdminPortal, but I am trying to call a controller action that is not in Admin Portal. I have this code but it automaticaly assigns /AdminPortal to the start of the url.

string tokenVerificationUrl = Url.Action(nameof(AccountController.VerifyEmail).AspName(), nameof(AccountController).AspName(),
            new {id = user.Id, token = emailConfirmationToken }, Request.Scheme);

Returns localhost:1234/AdminPortal/Account/VerifyEmail/tokenValue

I want it to return localhost:1234/Account/VerifyEmail/tokenValue

CodePudding user response:

To remove the area, simply add area = "" to the values being passed.

string tokenVerificationUrl = Url.Action(nameof(AccountController.VerifyEmail).AspName(), nameof(AccountController).AspName(),
        new { area = "", id = user.Id, token = emailConfirmationToken }, Request.Scheme);
  • Related