Muhammad Ali
Muhammad Ali

Reputation: 97

URL issue in asp.net core

I am implementing confirm email functionality. I am sending an account activation email to users with activation link in the email. I am trying that when user clicks on the link in the email, it will redirect the user to one of my method ConfirmEmail that takes two parameters user which is encrypted email and code. When I click on the link with debugger set to that ConfirmEmail method it does not hit there.

 var htmlContent = "<h4>Click on the link below to confirm your<b> Hello World</b> account:</h4>"
                                         + "</br>"
                                         + "<a href=https://localhost:44372/api/User/ConfirmEmail?user=" + EncryptedEmail + "&code=" + code + ">Activate Account</a>";

ConfirmEmail Method:

        [HttpGet]
        public IActionResult ConfirmEmail(string user, string code)
        {

            //Do work here
            return Ok();
        }  

Link in the email looks like this:
https://localhost:44372/api/User/ConfirmEmail?user=oBDULGKPcDaZoN89XcTtWnz%2f2m%2flFwfs&code=7250
Startup.cs Configure method:

 public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }

        app.UseHttpsRedirection();

        app.UseRouting();

        app.UseAuthorization();

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllers();
        });

    }

Upvotes: 1

Views: 413

Answers (1)

haldo
haldo

Reputation: 16711

It looks like this is an API controller, so you will need to add the route to the endpoint. You can do this by adding the route to the Http verb attribute. More info on attribute routing

[HttpGet("ConfirmEmail")]
public IActionResult ConfirmEmail(string user, string code)
{
}  

This will route the GET request to /api/user/confirmemail, whereas before it was probably routing to /api/user.

Upvotes: 1

Related Questions