Hi @Data Juggler
How can a static method either communicate with the Page instance
You can refer to the following sample to call the Static methods from the JavaScript function:
<script>
window.returnArrayAsync = () => {
DotNet.invokeMethodAsync('BlazorSample', 'ReturnArrayAsync')
.then(data => {
console.log(data);
});
};
</script>
Blazor component:
@page "/call-dotnet-example-1"
<h1>Call .NET Example 1</h1>
<p>
<button onclick="returnArrayAsync()">
Trigger .NET static method
</button>
</p>
@code {
[JSInvokable]
public static Task<int[]> ReturnArrayAsync()
{
return Task.FromResult(new int[] { 1, 2, 3 });
}
}
More detail information, see Call .NET methods from JavaScript functions in ASP.NET Core Blazor.
How can I send a 404 to a blocked IP address from a static method
Since the .NET method is a static method, you can't use the NavigationManager, in this scenario, you can return the checked result to the JavaScript function, then use the window.location.href
to refresh the page and change the url. Code like this:
[Note] in the LogIPAddress method, you need to return a sting result (checked result) to the JavaScript function, refer to the above sample.
DotNet.invokeMethodAsync('PixelDatabase.Net', 'LogIPAddress', response.ip)
.then(str => {
alert(str); //get the checked result
//then based on the result to set the window.location.href to change the url. like this:
window.location.href = window.location.protocol + '//' + window.location.host + "/404";
});
Does Azure have any way to block IP addresses from my VM?
This is another question, you'd better to create a new thread with the Azure tag and ask for help from the Azure team.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Dillion