Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate Reset Password link in WebApi

I wanted to generate a reset password link to send to the user's email that will open the ResetPassword page. On this page I will fill in the details regarding the new password and then confirm the password.

For this I have followed this Link

But there is a Url.Action method that i am not able to find in my web api project.

var callbackUrl = Url.Action(
               "ConfirmEmail", "Account", 
               new { userId = user.Id, code = code }, 
               protocol: Request.Url.Scheme);

Hase anybody done the reset password part in the web api? I need some help.

like image 462
loop Avatar asked Jun 13 '14 10:06

loop


People also ask

How do I create a password protected link in HTML?

WebSecurity - ResetPassword() The ResetPassword() method resets a user password using a password token.


2 Answers

You can use Url.Link in Web API 2.0

var callbackUrl = Url.Link("Default", new { Controller = "Account", 
                  Action = "ConfirmEmail", userId = user.Id, code = code });
like image 194
Volen Avatar answered Sep 18 '22 12:09

Volen


Url.Action does not exist because the Url helper in WebApi doe snot have the Action method. You can use Url.Route instead to generate the same thing but you will need to create a named route in order to use that method. If you are using attribute routing it, you can add a name to the route attribute like so:

[Route(Name="ConfirmEmail")]

and the helper would be

var callbackUrl = Url.Route("ConfirmEmail", new { userId = user.Id, code = code });
like image 37
Slick86 Avatar answered Sep 19 '22 12:09

Slick86