Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing server address in asp.net

Tags:

asp.net

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.

like image 857
RStyle Avatar asked May 17 '15 15:05

RStyle


1 Answers

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

like image 79
Behzad Avatar answered Nov 05 '22 22:11

Behzad