C# 在URI中使用IP而不是localhost

C# 在URI中使用IP而不是localhost,c#,asp.net,uri,C#,Asp.net,Uri,我目前正在尝试使用以下LOC创建指向API函数的有效链接: Uri locationHeader = new Uri(Url.Link("GetUserById", new { id = user.Id })); 这将返回以下内容: http://localhost:53800/..../user/821105b1 http://192.168.0.12:53800/..../user/821105b1 但是,由于链接应该可以从网络访问,因此我需要以下内容: http://localhos

我目前正在尝试使用以下LOC创建指向API函数的有效链接:

Uri locationHeader = new Uri(Url.Link("GetUserById", new { id = user.Id }));
这将返回以下内容:

http://localhost:53800/..../user/821105b1
http://192.168.0.12:53800/..../user/821105b1
但是,由于链接应该可以从网络访问,因此我需要以下内容:

http://localhost:53800/..../user/821105b1
http://192.168.0.12:53800/..../user/821105b1
我怎样才能得到这个结果而不是本地主机的结果


提前谢谢

调用本地库只会为您提供本地IP。您可以调用诸如whatismyip或checkip之类的外部API来获取外部IP。请参见此处…

0.12
您的服务器的本地ip地址吗?将项目的Web设置URL更改为可能会有所帮助。我只需要LAN内部ip,而不需要外部ip。没有本地的图书馆可以管理这个?