asp.net-mvc - 从 Controller 获取基本 URL 的最佳方法是什么

标签 asp.net-mvc

在我的 Controller 中,我将如何获得基本 URL。

例如,如果我的网址是:

http://www.mysite.com/MyController/MyAction

我想要一个返回的函数:
http://www.mysite.com

最佳答案

我用:

Request.Url.GetLeftPart(UriPartial.Authority);

关于asp.net-mvc - 从 Controller 获取基本 URL 的最佳方法是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8638962/

相关文章:

asp.net - ASP.NET 5 和 Razor 4 中 @helper 指令的正确替代方法是什么?

c# - 将 Web API 用于 Windows 服务以通过轮询接收命令和执行任务?

asp.net-mvc - MVC.NET 中的 ViewBag 与模型

asp.net-mvc - ASP.NET Mvc 站点中登录用户的自定义目录

asp.net-mvc - MVC 将对象的 Json 集合绑定(bind)到 Controller 操作

asp.net-mvc - AngularJS $routeProvider 和 ASP.NET MVC 中的相对 URL

asp.net-mvc - MVC 访问布局页面 View 模型

c# - MVC Controller 的 AJAX 参数不是 NULL?

c# - 异步方法不返回 asp.net mvc 4

c# - 查看asp.net mvc和asp.net core mvc的目录编译时间差异