Click here to Skip to main content
15,843,200 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:

I have a razor page called
page with directive
@page "/ForgetPasswordOtp/{UserName}"
. How can I prevent the same page access from another browser tap. It is causing a problem like everyone can access the page and resent the otp again and again. I need to prevent the page from another browser tab. In Index.razor page I already written a below code for prevent back.

What I have tried:

        function preventBack() { window.history.forward(); }
        setTimeout("preventBack()", 0);
        window.onunload = function () { null };

And inside ForgetPasswordOtp.razor page calling the function on

protected override async Task OnInitializedAsync()
 await JsRuntime.InvokeVoidAsync("preventBack");

Like wise how can I prevent the resend otp page from another browser's tab?

Updated 5-Aug-23 12:33pm

1 solution

You would need to throttle the requests on the server side using a timed cache of the username as it is the only data being passed. Then when the server receives the request, check the cache and either allow the process to continue or return a throttled response.

As you're doing Blazor development, I would look into using Asp.Net Core's Rate limiting middleware in ASP.NET Core | Microsoft Learn[^]
Share this answer
Rajesh Kumar 2013 9-Aug-23 0:45am    
Hi, I am trying to find a solution this way Solution Link. Is this a proper solution for me?
Rajesh Kumar 2013 9-Aug-23 4:05am    
Yes I can solve the issue by referring the Link

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