gpt4 book ai didi

c# - 在 Startup.cs 的 Configure 中获取域名或主机名和端口

转载 作者:太空宇宙 更新时间:2023-11-03 18:52:06 24 4
gpt4 key购买 nike

我需要帮助获取我的应用程序的主机名/域名和端口。

到目前为止,这是我在 Startup.cs 中的 Configure 方法中的示例代码:

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
var url = ""; // something that will get the current host/domain and port of the running applicaiton.

RecurringJob.AddOrUpdate<ISomething>(i=>i.SomethingToExecute(url), Cron.Daily);
}

因为我需要将 url 字符串传递给我的 SomethingToExecute 方法

public class Something : ISomething 
{
public void SomethingToExecute(string url){
...
Debug.WriteLine(url)
}
}

最佳答案

根据这个Github Issue以及 ASP.NET Core 团队的回应:

It's not possible. You need to read this information directly from config. The server does not read the endpoint configuration until it's ready to start the application (after Startup). Even then, that information would be inaccurate much of the time due to reverse proxy setups like IIS, Nginx, docker, etc..

关于c# - 在 Startup.cs 的 Configure 中获取域名或主机名和端口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55369411/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com