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

I have a razor page called
C#
ForgetPasswordOtp.razor
page with directive
C#
@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:

JavaScript
<script>
        function preventBack() { window.history.forward(); }
        setTimeout("preventBack()", 0);
        window.onunload = function () { null };
    </script>

And inside ForgetPasswordOtp.razor page calling the function on
C#
OnInitializedAsync()

C#
protected override async Task OnInitializedAsync()
    {
 await JsRuntime.InvokeVoidAsync("preventBack");
}

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

Thanks
Posted
Updated 5-Aug-23 11:33am

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
 
Comments
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