5

when I compile my project it runs in the url http://localhost:12421/index.html

Can I run it in my private ip? lets say http://192.168.1.212:12421/index.html I tried to browse that and it gave me error Bad Request - Invalid Hostname

HTTP Error 400. The request hostname is invalid.

HaveNoDisplayName
  • 8,291
  • 106
  • 37
  • 47
RStyle
  • 875
  • 2
  • 10
  • 29

3 Answers3

2

From where are you trying to access? The machine from where you're trying to access must be in the same network, if it is check that you are not blocking the connection on the Firewall (possibly the windows' firewall). Are you using IIS or IIS Express? If you're using IIS Express you'll need to to edit applicationhost.config file manually and change bindingInformation '::'.

Rui Lima
  • 7,185
  • 4
  • 31
  • 42
2

For example I have an ASP.NET project by name myWebSite.
The below ways to change the http://localhost:12421/ server address to a IP address for e.g: 192.168.1.7:80 always worked for me.

  1. Enable IISExpress on your computer

Windows Features

  1. Add a NetShare Reservation Open your Command Line (CMD) Run As Administrator in Windows and go to c:\Windows\system32>, then type:
    netsh http add urlacl url=http://192.168.1.7:80/ user=everyone and then press Enter key.
    You should be seen a URL reservation successfully added message.

CMD

  1. Go to C:/Users/UserName/Documents/IISExpress/config/ and open applicationhost.config.
    In the applicationhost.config file find your site in the <sites> section.
    Example:
<sites>
    <site name="myWebSit" id="1">
        <application path="/" applicationPool="Clr4IntegratedAppPool">
            <virtualDirectory path="/" physicalPath="D:\myWebSit\myWebSit" />
        </application>
        <bindings>
            <binding protocol="http" bindingInformation="*:12421:localhost" />
        </bindings>
    </site>
</sites>

Now change address to your IP instead localhost. For e.g:

<binding protocol="http" bindingInformation="*:80:192.168.1.7" />
  1. Change Project Url to own address
    Open your project on Visual Studio; Right click on your start up project and select properties. In the properties select Web tab and then change Project Url text box contents to your address. For e.g: http://192.168.1.7:80/ and click on Create Virtual Directory button.
    You should be seen a The virtual directory was created successfully. message.

VSWebTab

Now, you should be able to run your project in Visual Studio by own IP address.

Reference

Behzad
  • 3,502
  • 4
  • 36
  • 63
1

Generally when you run asp.net app from visual studio, it runs from the asp.net development server installed. so, it will run in localhost:port. But if you want to run using ip address then you have to use iisexpress and give port number with ip address in vs project->properties->web. follow the steps as follows given in the address: https://forums.adobe.com/thread/1486251

Are you trying to browse your app after deploying on IIS? To browse using ip address on IIS check out as follows:

  1. check if you can ping the server pc by pinging ip in command prompt.
  2. check if firewall is blocking. if so turn your firewall off.
  3. go to application pool after deploying on IIS
  4. select your application inside pool and select binding
  5. bind to your ip address and give a port number that is not occupied.

Thanks

Rashedul.Rubel
  • 3,446
  • 25
  • 36
  • In visual studio under properties>Web. It says unable to create virtual directory. You must specify localhost for the server name. – RStyle May 17 '15 at 17:43
  • do you want to run in visual studio with ip address? – Rashedul.Rubel May 17 '15 at 18:50
  • i was performing the last step on that url https://forums.adobe.com/thread/1486251 Anyway, my apppool only shows defaultAppPool. Is it correct? under Sites: There is only Default Web Site – RStyle May 18 '15 at 01:24
  • no under application pool there has to be a pool of your published copy. ex. if you publish your app named as 'abc', then inside application pool there has to be 'abc' and it's status has to be started. s – Rashedul.Rubel May 18 '15 at 05:12
  • but except visual studio if you want to browse using ip after publishing in iis then select the published file in iis, select binding. and in the sit binding dialogue give ip address and port number that is not used elsewhere. – Rashedul.Rubel May 18 '15 at 05:18
  • Ok this is what i did so far. Right click project in VS and publish to inetpub/wwwroot folder. Then i open IIS Manager> Add website>Sitename="testing"> Application Pool= DefaultAppPool >Physical Path = "C:\inetpub\wwwroot" >Binding is http:\\192.168.1.212:80, hostname i left it blank – RStyle May 18 '15 at 14:11
  • I then added Default Document>index.aspx. When i try to browse it i get HTTP Error 404.3 - Not Found. Then i manually went to the folder and open it and i get "This page contains the following errors: error on line 1 at column 2: StartTag: invalid element name" – RStyle May 18 '15 at 14:12
  • These are my starting code. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="index.aspx.cs" Inherits="WebApplication5.index" %> – RStyle May 18 '15 at 14:17
  • publish your application in a folder. then copy the folder and paste into inetpub->wwwroot folder. right click on the folder and convert it to application. select your application and go to binding. give ip and port number. – Rashedul.Rubel May 18 '15 at 18:41
  • Thanks i found the mistake. http://stackoverflow.com/questions/6425442/http-error-404-3-not-found-in-iis-7-5 – RStyle May 19 '15 at 01:12