有这个小演示:
控制器:
public class CrotolamoController : ControllerBase
{
[HttpPost]
[Route("/")]
public async Task<String> test()
{
return "hello world";
}
}
launchSettings.json:
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "https://www.crotolamo.com",
"sslPort": 443
}
},
"profiles": {
"Test": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "https://www.crotolamo.com",
"sslPort": 443,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
在Visual Studio上正确部署,但遗憾的是Postman无法向其发送HTTP POST请求
错误:getaddrinfo ENOTFOUND www.crotolamo.com
使用IIS和Windows Server 2019部署应用程序时会出现相同错误。使用以下配置:
绑定:
- 类型:https
- IP地址:全部未分配
- 端口:443
- 主机名www.crotolamo.com
- SSL证书:IIS Express开发证书
错误相同。
问题
它的唯一工作方式是使用localhost。我如何更改我的配置,以使用这个自定义域代替localhost?任何帮助都将不胜感激。
我尝试的事情没有成功
将行添加到我的Windows 10开发机器上的主机文件
127.0.0.1 www.crotolamo.com
用户Lex Li向我提供了以下解决方案提示:经过以下更改,在自定义域上运行的Visual Studio 2022项目现在可以从浏览器或开发机器中的Postman进行浏览。
launchSettings.json
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "https://www.crotolamo.com",
"sslPort": 443
}
},
"profiles": {
"Chostomo": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "https://www.crotolamo.com",
"sslPort": 443,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
在主机文件中,添加以下行:
- 127.0.0.1 crotolamo.com
- 127.0.0.1 www.crotolamo.com
然后编辑文件
.vs\yorProject\config\applicationhost.config
原始
<site name="WebSite1" id="1" serverAutoStart="true">
<application path="/">
<virtualDirectory path="/" physicalPath="%IIS_SITES_HOME%WebSite1" />
</application>
<bindings>
<binding protocol="http" bindingInformation=":8080:localhost" />
</bindings>
</site>
已更改
<site name="WebSite1" id="1" serverAutoStart="true">
<application path="/">
<virtualDirectory path="/" physicalPath="%IIS_SITES_HOME%WebSite1" />
</application>
<bindings>
<binding protocol="http" bindingInformation=":8080:localhost" />
<binding protocol="https" bindingInformation="*:443:" />
</bindings>
</site>
仍在等待在Windows Server 2019上对IIS实施更改,将相应地编辑帖子。