English 中文(简体)
Asp.Net Core 6.0 Core identity Framework Forgot Password t Work
原标题:Asp.Net Core 6.0 Core Identity Framework Forgot Password Doesn t Work

I am working on asp.net core 6 identity framework. when I tried to use the forgot password link on the login page, it goes to /Identity/Account/ForgotPassword page. When I click the "Reset Password" link on the page, it goes to /Identity/Account/ForgotPasswordConfirmation and I get an email to the email entered in the textbox.

电子邮件机构希望:

请在此点击你的密码。

当我检查 Chrome的“在这里点击”时,可以看出:

Please reset your password by clicking here

When I clicked the "clicking here" link in the email, the application is loaded with the URL shown below https://localhost:44302/Identity/Account/ResetPassword?code=Q2ZESjhFQzRGRVN6eFZwS21jK045R1ZFQ0lJa0VZZmN1V1lsN0tMUTFkYVB5YTVuYWlkQWd2NU5Rd25oQk8ydy9ZNURXdkNqSmx1MWltemFSUUZRWHJ6dnNTcVJGR1pKZWJPWHE2MVZlUi9ZN0J6NXJtWXYrcW8vbFdJcUVRVjBVd2VBSU9zYU94eC9DcE1tN2dxWE9Ja09kTUlDTTFOWjZJSlZsQmQ1aWdEd3B6UGVOZkRBdEdsbmNxZ2pEaGRlWHJYRDl4dTZlV3UyaWF1dlRIdkEzUExzanJPZHFmTVQ2bzYvMDlBc21rLzJNNjhE

在所展示的网页上,我只链接了“Resend Code”。 我在这里 st。 ResetPassword.cshtml.cs Razor page has this Code

public IActionResult OnGet(string code = null)
    {
        if (code == null)
        {
            return BadRequest("A code must be supplied for password reset.");
        }
        else
        {
            Input = new InputModel
            {
                Code = Encoding.UTF8.GetString(WebEncoders.Base64UrlDecode(code))
            };
            return Page();
        }
    }

    public async Task<IActionResult> OnPostAsync()
    {
        if (!ModelState.IsValid)
        {
            return Page();
        }

        var user = await _userManager.FindByEmailAsync(Input.Email);
        if (user == null)
        {
            // Don t reveal that the user does not exist
            return RedirectToPage("./ResetPasswordConfirmation");
        }

        var result = await _userManager.ResetPasswordAsync(user, Input.Code, Input.Password);
        if (result.Succeeded)
        {
            return RedirectToPage("./ResetPasswordConfirmation");
        }

        foreach (var error in result.Errors)
        {
            ModelState.AddModelError(string.Empty, error.Description);
        }
        return Page();
    }

当我通过该守则时,只采用了“OnGet()”方法,而不是“OnPostAsync()”方法。

问题回答

取代<代码>Return 的使用HttpClient(:

var content = new StringContent(JsonSerializer.Serialize(Input), UnicodeEncoding.UTF8, "application/json");
await new HttpClient().PostAsync("InputModel", content);

OnGetAsync:

public async Task OnGetAsync(string code = null)
{
    if (code == null)
    {
        return BadRequest("A code must be supplied for password reset.");
    }
    else
    {
        Input = new InputModel
        {
            Code = Encoding.UTF8.GetString(WebEncoders.Base64UrlDecode(code))
        };
        var content = new StringContent(JsonSerializer.Serialize(Input), UnicodeEncoding.UTF8, "application/json");
        await new HttpClient().PostAsync("InputModel", content);
    }
}

OnPost:

public async Task<IActionResult> OnPostAsync(InputModel Input)
{
    //Your Code
    return Page("ConfirmedEmail");
}

Then create another page to confirmed alert by name ConfirmedEmail





相关问题
.NET 7 minimal API request timeout

I found this in .NET 8 (prerelease) but I can t use it due to company policy. https://learn.microsoft.com/en-us/aspnet/core/performance/timeouts?view=aspnetcore-8.0&viewFallbackFrom=aspnetcore-7.0 ...

Blazor web assembly pass checkbox list values to model

I m new to Blazor. I m working in a web assembly Blazor project. I am trying to create a form that passes values back to a model. I have it working with input text fields and drop downs, but I am ...

asp.net 6 c# mvc one to many get data from many side

I am trying to access the data on the many side of a one to many relationship. In the Index action of my controller I assign the data to a variable and return it. I have a Blog, the one side, with ...

How to update shared view adminheader.cshtml from a model

I ve added a drop down into my shared adminheader.cshtl view and it needs to be dynamically updated from data from a table. So when I use another view like routeplan.cshtml I load the view from ...

Gitlab CI On Prem, Docker Image and ASP.NET Core 7

We have a .NET 6 application. We added CI using: image: mcr.microsoft.com/dotnet/sdk:6.0 before_script: - dotnet restore --packages $NUGET_PACKAGES_DIRECTORY build: stage: build script: - ...

ASP.NET Core 2 .1 - How to show all data in table

I don t know how to put CustomerData into CustomerLists property. I m already using CustomerLists = CustomerData; but I got error: CustomerLists is a type but is used like a variable Can anyone ...

热门标签