質問

I'm trying to define an alias to localhost in development ambient in Visual Studio 2013.

When I used previous versions of Visual Studio, I used the Visual Studio Development Server to debug and the only thing I needed to do was to change my hosts file adding this entry:

127.0.0.1   localhost    
127.0.0.1   localhostalias

I'm having problems to do this with VS2013. I've browsed all over the internet and I've tried the following things, but I'd like someone of you to tell me what am I doing wrong. I've obviously already changed the hosts file...

In the web project Properties -> Web in the section Servers where IIS Express is selected as default, I tried changing http://localhost:53944 to http://localhostalias:53944 but an error is showed saying: "Unable to create the virtual directory. Cannot create the Web site 'http://localhostalias:53944'. You must specify "localhost" for the server name".

I also tried changing the applicationhost.config which is located in <>\IISExpress\config to

        <site name="<<Site name>>" id="2">
            <application path="/" applicationPool="Clr4IntegratedAppPool">
                <virtualDirectory path="/" physicalPath="<<Site Path>>" />
            </application>
            <bindings>
                <binding protocol="http" bindingInformation="*:53944:*" />
            </bindings>
        </site>

And when I opened the project it was changed to

        <site name="<<Site name>>" id="2">
            <application path="/" applicationPool="Clr4IntegratedAppPool">
                <virtualDirectory path="/" physicalPath="<<Site Path>>" />
            </application>
            <bindings>
                <binding protocol="http" bindingInformation="*:53944:*" />
            </bindings>
        </site>
        <site name="<<Site name>>(1)" id="3">
            <application path="/" applicationPool="Clr4IntegratedAppPool">
                <virtualDirectory path="/" physicalPath="<<Site Path>>" />
            </application>
            <bindings>
                <binding protocol="http" bindingInformation="*:53944:localhost" />
            </bindings>
        </site>

Can someone help me?

Thanks in advance,

Camilo

役に立ちましたか?

解決

If you reach this page looking for a solution for VS2015+, the applicationhost.config file you are looking for is no longer on documents\IISExpress\config.

The new location is {solutiondir}\.vs\config\applicationhost.config.

他のヒント

Since the linked URL from Jack's answer is currently not working, and the solution (at least for me) was covered in the answer to another question, I will repeat the answer here:

You can have multiple bindings set. Therefore, you can setup bindings for every external address you wish to serve on, and it will work:

<bindings>
    <binding protocol="http" bindingInformation=":1904:" />
    <binding protocol="http" bindingInformation=":1904:machineName" />
    <binding protocol="http" bindingInformation=":1904:10.1.10.123" />
</bindings>

I encountered a similar error here, and it turned out that the solution could be found at: http://stonycreektechnologies.com/2011/03/15/iis-express-enable-remote-requests/

For me, this was just a case of running the command there (I used it for port 8080 and for the port for my project, 55968, just to be sure) and closing and reopening my project, editing my applicaitonhost.config file, and then changing the settings of the site through the visual studio gui.

The other thing to be careful of is that you may get multiple entries for your port number in the applicationhost.config file. This is bad, you only want the one, so you're safe to cull off the other entries with the same port.

For those who come here for the same error "cannot create the web site you must specify localhost for the server name" using visual studio 2019 2022, you may check: .csproj.user file under your project folder, may have set false to some configurations at some point like I did, I set UseIISExpress to false didn't know when.

Good luck!

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top