代码改变世界

关于 ASP.NET MVC 与 ASP.NET Core MVC 中获取当前主机 Host 值的区别

2020-12-17 23:59  音乐让我说  阅读(463)  评论(0编辑  收藏  举报

1. ASP.NET MVC

示例代码:

string host = urlHelper.RequestContext.HttpContext.Request.Url.Host;

 

 

2. ASP.NET Core MVC

示例代码:

    string host = urlHelper.ActionContext.HttpContext.Request.Host.Host;

运行截图(ASP.NET Core MVC):

 

谢谢浏览!