Click here to Skip to main content
15,923,789 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm calling Url.Action from a .net core api so there is no page url root to call upon.

How can I pass one in?

What I have tried:

This is the original code (not doing the job):
string confirmationLink = Url.Action("SetPassword",
  "Account", new
  {
      userid = userMaster.Id,
      token = confirmationToken
  },
 protocol: HttpContext.Request.Scheme);


Here are some of my efforts - two return null, the middle one does not build:
var aUrl = Url.RouteUrl("https://localhost:5101/", new  { id = "MailRoot", category = "confirmationURLs" });
                Url.RouteUrl uri1 = new Url("http://mypage.com/");
               var url2 = Url.RouteUrl("MailRoot", "https://localhost:5101/");


The final outcome needs to be something like this:

Please confirm your account by clicking this <a href='https://localhost:5101/Account/SetPassword?userId=6fb79cd9-2030-494a-aade-47c770a9f0da&token=ALongToken'>link</a>.

Workaround: building the link as a plain string - carefully!
This does not answer the question asked, but it provides me with a functional solution that I can proceed with:
string confirmationLink =              ${this.config.p_ConfirmationURLRoot}/{this.config.p_ConfirmatonURLController}/{this.config.p_ConfirmationURLAction}?userId={ userMaster.Id}&token={ confirmationToken}";
Posted
Updated 17-Nov-19 20:14pm
v5
Comments
Richard Deeming 18-Nov-19 14:29pm    
How about:
string confirmationLink = Url.Action("SetPassword", "Account", new { ... }, protocol: "https");

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900