如何为新的MVC 5项目在localhost之外指定自定义URL?

问题描述

我创建了一个新的MVC 5项目,并且尝试将其项目URL配置为本地IIS上localhost之外的项目。 http://alpha.domain.local。使用新的WebForms项目很容易做到这一点,但是MVC 5提供了一些阻力。

我已在我的hosts文件中设置了一个条目:

127.0.0.1    alpha.domain.local

...并且我已经使用正确的主机头在IIS中创建了站点:

enter image description here

enter image description here

这是我尝试的项目配置:

enter image description here

...以及尝试保存时出现的错误:

enter image description here

enter image description here

当我单击Create Virtual Directory按钮(即使它已经存在)时,也会得到以下内容:

enter image description here

我可以ping它:

enter image description here

我可以浏览到它:

enter image description here

我只是无法将我的MVC 5项目指向该项目。 MVC 5顽固地坚持我使用localhost,这是我不想做的。我已经建立了一些依赖于本地IIS中这些自定义主机名的基础结构。

This Q&A 种类很明确,但不是很清楚。

就像我说的那样,这对于新的WebForms项目(VS 2019,最新版本)非常有效。我已经做了很多年了。现在,我终于开始使用MVC,这有点麻烦。我将不得不重做一堆无法正常工作的东西。

这可能吗?其他人能做到吗?

解决方法

好的,知道了。 (没多久!)

由于某些原因,MVC 5项目将不接受属于子域的项目URL,例如http://alpha.domain.local,而WebForms项目可以。

我将URL切换为http://domain.alpha,它可以工作。你挠我的头,我挠你的头。但是问题解决了。去搞清楚。我不会试图破译Microsoft的变化。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...