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

102 views Asked by At

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

1

There are 1 answers

0
RobertDev22 On BEST ANSWER

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);