【问题标题】:Is it possible to create subdomains for localhost based on different ports?是否可以根据不同的端口为 localhost 创建子域?
【发布时间】:2020-02-11 14:37:39
【问题描述】:

当我需要将 cookie 从一个本地应用程序共享到另一个应用程序时,我遇到了这种情况。我想知道是否可以通过使应用程序的地址之一 localhost:number 成为另一个 localhost 的子域来实现它?

提前致谢。

【问题讨论】:

  • C:\Windows\System32\drivers\etc\hosts文件中定义不同的域和子域。
  • 如果您在 IIS 中托管应用程序,您可以进行 URL 重写:weblogs.asp.net/owscott/…
  • 您也可以使用通配符在主机中指定127.0.0.1 *.localhost.com

标签: c# asp.net asp.net-mvc asp.net-core asp.net-web-api


【解决方案1】:

如果您使用端口,则它不是子域,而是不同的域。

如果您确实需要子域,请在 hosts 文件中设置它

在 Windows c:\windows\system32\drivers\etc\hosts

在 Linux 中/etc/hosts

127.0.0.1    domain.test
127.0.0.1    subdomain.domain.test

【讨论】:

  • 不确定我是否理解这将有什么帮助
  • 如果您只想测试不同应用程序之间的 cookie 共享,请使用不同的端口。对于 cookie 的 localhost:3000 和 localhost:4000 - 这是一个不同的域。但是,如果您只有一个应用程序实例,它应该具有不同的逻辑取决于子域 - 使用 hosts 文件。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-16
  • 2023-03-29
  • 1970-01-01
  • 2018-04-14
  • 2021-02-11
相关资源
最近更新 更多