You can use a third party API, such as Ipify, to get the IP address of the current request in Blazor. The script api.ipify will return the IP address in JSON format. But this is a workaround. As of now, there is no way to achieve this. In the following code snippet, the IP address will be retrieved from the Ipify API through a JS interop call to the Blazor server.


function GetAddress() {
    var script = document.createElement("script");
    script.type = "text/javascript";
    script.src = "";
function DisplayIP(response) {
    document.getElementById("text").innerHTML = "Your IP Address is " + response.ip;

@page "/"
@inject IJSRuntime jsRuntime

<button @onclick="GetIp">Get IP!!!</button>
<textarea id="text" style="width:50%;height:40px;" />

          public async Task GetIp()
                 await jsRuntime.InvokeAsync<object>("GetAddress");


Last modified: June 16, 2021



Write a Reply or Comment