【问题标题】:Not sure how I can determine my ASP.NET website domain and port, programatically不知道如何以编程方式确定我的 ASP.NET 网站域和端口
【发布时间】:2013-06-07 07:14:42
【问题描述】:

在我的 global.asax 中,我正在通过 AutoFac 为 DI/IoC 连接一些服务。

其中一个服务想知道当前网站的域名和端口

例如:-

builder.RegisterType<AuthenticationService>()
                .As<IAuthenticationService>()
                .WithParameter("localhostServer", new Uri(?????))
                .SingleInstance();

这是一些配置的东西。

当我在global.asax Application_Start() 中执行此操作时,我不知道如何通过新的 Uri 实例传递服务器 ip 和端口

更新:服务器 == IIS7,集成模式。 (不是 iis6 或经典模式)。

【问题讨论】:

标签: c# .net iis-7 domain-name


【解决方案1】:

我认为没有确定的方法可以做到这一点:

  • IIS 可以将多个 ip、主机名和端口映射到 Web 应用程序
  • 每个请求都可以绑定到不同的请求

您可能需要执行以下操作之一:

  • 更改您的代码,以便仅在您有请求时才需要绑定,而不是在应用程序启动时需要绑定
  • 如果您事先知道正确的值,您可以通过配置键存储它来设置它

【讨论】:

  • Heya :) 我担心你可能会建议这 exact 两个选项,因为那是 exact 我一直在绞尽脑汁想要解决的问题,因为最后一小时:) [配置建议现在看起来是最好的]
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-09-30
  • 1970-01-01
  • 1970-01-01
  • 2015-09-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多