【发布时间】:2017-06-02 12:39:50
【问题描述】:
下面是asp.net框架中的代码
protected HttpResponseMessage Created<T>(T apiResponse, ObjectId id) where T: ILinking
{
//var builder = new UriBuilder();
Uri uri = new Uri(this.RequestUri(), id.ToString());
apiResponse.get_Links().Add(new ApiLink(uri, "created", HttpMethod.Get));
HttpResponseMessage message = base.Request.CreateResponse<T>(HttpStatusCode.Created, apiResponse);
message.Headers.Add("Location", uri.ToString());
return message;
}
我想将它迁移到 asp.net core 中。我用谷歌搜索了很多,但找不到任何解决方案。如何在 asp.net core 中声明 this.RequestUri()?
提前致谢。
【问题讨论】:
-
我在 .NET 世界中相对较新,但我在 6 个月前开始使用 ASP.NET Core 1.0(所以我没有以前版本的参考),但我猜你想要获取用户的实际 URI 吗?在这种情况下,下面的代码可以帮助你:
string host = context.Request.Host.ToString();string path = context.Request.Path.ToString(); -
您最初的
RequestUri()方法是怎样的?这不是标准方法。然而,假设它只返回当前请求 URI,你可以简单地使用this.Request.RequestUri -
什么是“这个”?
-
见 GetEncodedUrl github.com/aspnet/HttpAbstractions/blob/dev/src/…
标签: c# asp.net asp.net-core