1

I have a blazor application. I use Azure AD B2C for authentication. When I am trying to run a sign in user flow, I get

This site can’t be reached

localhost refused to connect.

Here is my launchSettings.json:

{
  "iisSettings": {
  "windowsAuthentication": false,
  "anonymousAuthentication": true,
  "iisExpress": {
    "applicationUrl": "http://localhost:54925",
    "sslPort": 44333
  }
},
"profiles": {
  "IIS Express": {
    "commandName": "IISExpress",
    "launchBrowser": true,
    "environmentVariables": {
      "ASPNETCORE_ENVIRONMENT": "Development"
    }
  },
  "MyAppName": {
    "commandName": "Project",
    "launchBrowser": true,
    "environmentVariables": {
      "ASPNETCORE_ENVIRONMENT": "Development"
    },
    "applicationUrl": "https://localhost:5001;http://localhost:5000"
  }
}
}

This is from appsettings.json:

"AzureAdB2C": {
  "Instance": "https://laticreteb2c.b2clogin.com",
  "ClientId": "Set in Azure. For development, set in User Secrets (secrets.json)",
  "CallbackPath": "/signin-oidc",
  "Domain": "laticreteb2c.onmicrosoft.com",
  "SignOutCallbackPath": "/signout",
  "SignUpSignInPolicyId": "B2C_1_MyAppName_SignIn",

  "ResetPasswordPolicyId": "MyAppName_PasswordReset",
  "EditProfilePolicyId": "",
  "ClientSecret": "Set in Azure. For development, set in User Secrets (secrets.json)",
  "TenantId": "Set in Azure. For development, set in User Secrets (secrets.json)"
},

I am running my user flow with reply url https://localhost:5001/signin-oidc.

I know it used to work before, both locally and in production, and I cannot figure out what might break since then. How can I diagnose this issue?

David Shochet
  • 5,035
  • 11
  • 57
  • 105

1 Answers1

1

Please check if the following insights can help workaround:

This exception This site can’t be reached localhost refused to connect usually occurs when there is no service listening on the IP/port you are trying to connect to Or when trying to connect to the wrong IP/port.

  1. Try changing the port number
  2. Or You can even try to replace the localhost with your IP address.

And also do ensure there's no firewall blocking the connection.and whatever port you change , make sure same is given in appregistration reply url.

"profiles": {
        " MyAppName": {
            "commandName": "Project",
            "launchBrowser": true,
            "applicationUrl": https://localhost:44316/;http://localhost:3110 ,
            "environmentVariables": {
                "ASPNETCORE_ENVIRONMENT": "Development"
            },
         
        }
    }

Also please check if

  1. You have started your server.
  2. Your server is listening for connections or not.
  3. Try deleting cookies for your localhost
  4. Run Visual Studio as "Run as administrator"
  5. You have Granted admin consent for open id and offline access permissions in portal.

In App settings see if instance has to be something like :

"Instance": https://yourb2cdomain.b2clogin.com/tfp/

At last if issue is still there try to find the .vs folder & Obj folder and Delete them and run again.

References:

  1. GitHub - JagadeshDev : Creating A Blazor Server Azure B2C App
  2. BlazorADB2C/BlazorADB2C at master · bdnts/BlazorADB2C · GitHub
  3. Azure-Samples/active-directory-aspnetcore-webapp-openidconnect-v2 · GitHub

If you feel ,there is something wrong with the asp.net application configurations , you may give a try to check the issues that may cause the error here > asp.net mvc - localhost refused to connect Error in visual studio - Stack Overflow

kavyaS
  • 8,026
  • 1
  • 7
  • 19