如何在 IISExpress 上使用带有 localhost 的子域? [英] How to use subdomains with localhost on IISExpress?

查看:135
本文介绍了如何在 IISExpress 上使用带有 localhost 的子域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在通过 localhost:5252 在本地为我的 MVC 应用程序提供服务.

I'm serving my MVC app locally via localhost:5252 right now.

我正在尝试通过让 localhost 和 contoso.localhost 都指向我的 Web 应用程序实例来设置我的应用程序以测试多租户.

I'm trying to set up my app to test multi-tenancy by having both localhost and contoso.localhost point to my web app instance.

我用相应的条目设置了我的主机文件:

I set up my hosts file with the corresponding entry:

127.0.0.1       contoso.localhost

但是我不确定我还需要做什么才能完成这项工作.现在,当我导航时,我只是得到一个标准的 IIS8 页面,即使我没有在 IIS 管理器中做任何事情.

However I'm not sure what else I need to do to make this work. Right now I just get a standard IIS8 page when I navigate, even though I haven't done anything in IIS Manager.

我试图避免在本地使用 IIS,因为一切都在使用 IISExpress.有什么简单的方法可以实现吗?

I'm trying to avoid having to use IIS locally, as everything is working with IISExpress. Is there any easy way to achieve this?

推荐答案

这可以通过编辑applicationHost.config文件来完成

This can be accomplished by editing the applicationHost.config file

C:UsersyourProfileDocumentsIISExpressconfigapplicationHost.config

Visual Studio 通常会在您进行配置更改时为您处理编辑此文件,但您可以手动编辑.找到您正在使用的特定站点,并且以下绑定应该可以工作:

Visual Studio usually handles editing this file for you when you make configuration changes, but you can manually edit. Find the particular site you are working with and the following bindings should work:

<bindings>
   <binding protocol="http" bindingInformation="*:5252:localhost" />
   <binding protocol="http" bindingInformation="*:5252:contoso.localhost" />
</bindings>

您真的可以将端口更改为您想要的任何内容,这样您就可以使用 80 来节省一些输入.继续添加绑定以根据需要填写您的多租户.

You can really change the port to anything you want so you could use 80 to save yourself some typing. Continue adding bindings to fill out your multi-tenancy as needed.

如果您正在寻找更多信息,我建议您查看 Scott Hanselman 在 IIS Express 上的博文&SSL.

If you are looking for more information, I would recommend checking out Scott Hanselman's blog post on IIS Express & SSL.

与 VS 2015 &在 .NET 核心中,applicationHost.config 已移至基于目录的系统来存储配置,而不是全局配置文件.新位置与您的项目相关:

With VS 2015 & .NET core, the applicationHost.config has moved to a directory based system of storing the configuration instead of a global configuration file. The new location is relative to your project:

.vsconfigapplicationHost.config

相同的编辑原则适用于该文件,但是当使用 TFS 源代码控制 VS 不编辑在分支之间更改时文件,就像它对全局文件所做的那样.

The same editing principals apply to this file, but when using TFS source control VS does not edit the file when changing between branches as it did with the global file.

关于域的通配符注释,在 IIS 10 之前不支持通配符主机名.因此,IIS Express 10 可能支持它,但之前可能不支持.

Regarding the wildcard comment for domains, wildcarding hostname isn't supported until IIS 10. Therefore, it may be supported in IIS Express 10, but probably not before.

bindingInformation的细分为:

bindingInformation="<IPAddress>:<Port>:<Hostname>"

这篇关于如何在 IISExpress 上使用带有 localhost 的子域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆