Home > Software engineering >  Getting 'localhost refused to connect' on internet explorer. Then on Microsoft edge the pa
Getting 'localhost refused to connect' on internet explorer. Then on Microsoft edge the pa

Time:06-23

When I load visual studio 2022 it briefly says on start-up '(not responding)'.

Then it will continue to work. I will then load the project with internet explorer and it says 'hmmm... can't reach this page. localhost refused to connect.'

I then retry on Chrome and Microsoft Edge and the page loads but the images do not.

This is not just a problem on one specific project. It is the same on all projects.

appsettings.json

`{
"Logging": {
    "LogLevel": {
        "Default": "Information",
        "Microsoft": "Warning",
        "Microsoft.Hosting.Lifetime":
"Information"
    }
},
"AllowedHosts": "*",

"ConnectionStrings": {
    "DefaultConnection": 


"Server=.;Database=
HondaDealership;Trusted_Connection=True"
}

}`

launchSettings.json

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

Things I have tried:

  • changed the app url,
  • changed the sslPort,
  • uninstalled and re installed iis 10.0 express,
  • deleted .vs folder,
  • I am the administrator on my computer,
  • I restarted my computer.

Its worth noting again this problem is happening on all projects and all browsers.

HTML that should load images

`<div >
<h1 >
Seans Honda Dealership</h1>
</div>
<div >
<div id="image1" >
    <a href="/Crx">
        <img 
src="C:\Users\user\source\repos
\HondaDealership\HondaDealer 
ship\Images\Crx.jfif"
             
alt="..."width="350" 
height="225">
    </a>
</div>
<div id="image2" >
    <a href="/Eg6">
        <img 
src="C:\Users\user\source\repos\
HondaDealership\HondaDealership\
Images\Eg6.jfif"
            
alt="..." width="350" 
height="225">
    </a>
</div>
<div id="image3" >
    <a href="/Integra">
        <img src="C:\Users\user\source\repos\
HondaDealership\HondaDealership\
Images\Integra.jfif"
             
alt="..."width="350" 
height="225">
    </a>
</div>
</div>`

This is the error when I right-click on an image and go to inspect in Microsoft Edge.

   localhost/:129 
    
   Not allowed to load local resource: 
   file:///C:/Users/user/source/repos/
   HondaDealership/HondaDealership/Images
   /Crx.jfif

CodePudding user response:

You get the error in Edge because it is built on Chromium. And Chromium does not allow loading local resources when you're on a website due to security concerns. Technically localhost is just another website to the browser. So as far as it's concerned this is no different than you being on stackoverflow.com and it trying to load a file from your local computer.

You need to make your image source path be relative to your site's root directory, and place the image files in the matching location. So you should have a directory called images and the path would then be localhost:129/images/Crx.jfif.

  • Related