获取当前ASP.NET Web Api 2操作的URL
发布时间:2020-12-16 04:14:00 所属栏目:asp.Net 来源:网络整理
导读:在ASP.NET Web API 2中,如何获取当前操作的Url.以下是说明性示例. [HttpGet][Route("api/someAction")]public SomeResults GetAll(){ var url = /* what to write here*/ ....} 解决方法 ApiController基类的一个属性(必须从中派生自己的控制器)称为Request
在ASP.NET Web API 2中,如何获取当前操作的Url.以下是说明性示例.
[HttpGet] [Route("api/someAction")] public SomeResults GetAll() { var url = /* what to write here*/ .... } 解决方法
ApiController基类的一个属性(必须从中派生自己的控制器)称为Request:
// Summary: // Defines properties and methods for API controller. public abstract class ApiController : IHttpController,IDisposable { // ... // // Summary: // Gets or sets the HttpRequestMessage of the current System.Web.Http.ApiController. // // Returns: // The HttpRequestMessage of the current System.Web.Http.ApiController. public HttpRequestMessage Request { get; set; } // ... } 这使您可以访问具有以下方法的HttpRequestMessage: // // Summary: // Gets or sets the System.Uri used for the HTTP request. // // Returns: // Returns System.Uri.The System.Uri used for the HTTP request. public Uri RequestUri { get; set; } 使用Request.RequestUri获取当前操作的URL.它将返回一个Uri对象,使您可以访问请求的URI的每个部分. 最后,您可能会发现以下SO问题很有用: > How to get base URL in Web API controller? (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 线程是否在ASP.Net中的请求之间重用?
- asp.net-mvc-3 – OutputCache和自定义gzip压缩过滤器
- asp.net – MathJax – 文件无法加载:/extensions/MathZoo
- asp.net-mvc-3 – System.Web.Mvc.HandleErrorInfo错误的模
- asp.net-mvc – Azure网站上的字体文件404,看似正确的MIME
- js触发asp.net的Button的Onclick事件应用
- asp.net-mvc – 在ASP.NET MVC中重定向后发布
- asp.net-mvc – 使用其他bool字段进行MVC远程验证
- asp.net-mvc – 使用IIS 7中的ASP.NET MVC 1来路由具有特定
- asp.net-mvc – 如何使用MVCSiteMap进行隐式本??地化?
推荐文章
站长推荐
热点阅读