<legend id='W3Ctc'><style id='W3Ctc'><dir id='W3Ctc'><q id='W3Ctc'></q></dir></style></legend>
    • <bdo id='W3Ctc'></bdo><ul id='W3Ctc'></ul>
  • <tfoot id='W3Ctc'></tfoot>

      <small id='W3Ctc'></small><noframes id='W3Ctc'>

    1. <i id='W3Ctc'><tr id='W3Ctc'><dt id='W3Ctc'><q id='W3Ctc'><span id='W3Ctc'><b id='W3Ctc'><form id='W3Ctc'><ins id='W3Ctc'></ins><ul id='W3Ctc'></ul><sub id='W3Ctc'></sub></form><legend id='W3Ctc'></legend><bdo id='W3Ctc'><pre id='W3Ctc'><center id='W3Ctc'></center></pre></bdo></b><th id='W3Ctc'></th></span></q></dt></tr></i><div id='W3Ctc'><tfoot id='W3Ctc'></tfoot><dl id='W3Ctc'><fieldset id='W3Ctc'></fieldset></dl></div>

        与 Request.RequestURI 等效的 ASP.NET Core MVC 是什么?

        What is the ASP.NET Core MVC equivalent to Request.RequestURI?(与 Request.RequestURI 等效的 ASP.NET Core MVC 是什么?)
        • <bdo id='BefwH'></bdo><ul id='BefwH'></ul>
            <i id='BefwH'><tr id='BefwH'><dt id='BefwH'><q id='BefwH'><span id='BefwH'><b id='BefwH'><form id='BefwH'><ins id='BefwH'></ins><ul id='BefwH'></ul><sub id='BefwH'></sub></form><legend id='BefwH'></legend><bdo id='BefwH'><pre id='BefwH'><center id='BefwH'></center></pre></bdo></b><th id='BefwH'></th></span></q></dt></tr></i><div id='BefwH'><tfoot id='BefwH'></tfoot><dl id='BefwH'><fieldset id='BefwH'></fieldset></dl></div>

                <legend id='BefwH'><style id='BefwH'><dir id='BefwH'><q id='BefwH'></q></dir></style></legend>
                  <tfoot id='BefwH'></tfoot>

                  <small id='BefwH'></small><noframes id='BefwH'>

                    <tbody id='BefwH'></tbody>
                1. 本文介绍了与 Request.RequestURI 等效的 ASP.NET Core MVC 是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我找到了一个 博客文章 展示了如何将熟悉的东西(如 HttpResponseMessage)填充"回 ASP.NET Core MVC,但我想知道与以下代码执行相同操作的新本地方法是什么在控制器中的 REST Post 方法中:

                  I found a blog post that shows how to "shim" familiar things like HttpResponseMessage back into ASP.NET Core MVC, but I want to know what's the new native way to do the same thing as the following code in a REST Post method in a Controller:

                  // POST audit/values
                  [HttpPost]
                  public System.Net.Http.HttpResponseMessage Post([FromBody]string value)
                  {
                      var NewEntity = _repository.InsertFromString(value);
                  
                      var msg = new System.Net.Http.HttpResponseMessage(System.Net.HttpStatusCode.Created);
                      msg.Headers.Location = new Uri(Request.RequestUri + NewEntity.ID.ToString());
                      return msg;
                  
                  }
                  

                  在 ASP.NET Core MVC 项目中,我似乎无法获取 Request.RequestUri.

                  In an ASP.NET Core MVC project, I can't seem to get Request.RequestUri.

                  我尝试检查请求,并且能够创建这样的函数:

                  I tried inspecting Request, and I was able to make a function like this:

                  private string UriStr(HttpRequest Request)
                  {
                      return Request.Scheme + "://" + Request.Host + Request.Path; // Request.Path has leading /
                  }
                  

                  所以我可以改写 UriStr(Request).但我不确定这是否正确.我觉得我在乱用,并且没有正确使用它.

                  So I could write UriStr(Request) instead. But I'm not sure that's right. I feel like I'm hacking my way around, and not using this correctly.

                  早期非核心 ASP 的相关问题.NET MVC 版本询问如何获取站点的基本 url.

                  A related question for earlier non-Core ASP.NET MVC versions asks how to get the base url of the site.

                  推荐答案

                  更简洁的方法是使用 UriBuilder:

                  A cleaner way would be to use a UriBuilder:

                  private static Uri GetUri(HttpRequest request)
                  {
                      var builder = new UriBuilder();
                      builder.Scheme = request.Scheme;
                      builder.Host = request.Host.Value;
                      builder.Path = request.Path;
                      builder.Query = request.QueryString.ToUriComponent();
                      return builder.Uri;
                  }
                  

                  (未测试,代码可能需要一些调整)

                  (not tested, the code might require a few adjustments)

                  这篇关于与 Request.RequestURI 等效的 ASP.NET Core MVC 是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Performance overhead of using attributes in .NET(在 .NET 中使用属性的性能开销)
                  Accessing attribute info from DTE(从 DTE 访问属性信息)
                  c# Hide a property in datagridview with datasource(c#使用数据源隐藏datagridview中的属性)
                  Extract Display name and description Attribute from within a HTML helper(从 HTML 帮助器中提取显示名称和描述属性)
                  C# Attributes and their uses(C# 属性及其用途)
                  C# - Getting all enums value by attribute(C# - 按属性获取所有枚举值)
                2. <tfoot id='sR8OL'></tfoot>
                    <tbody id='sR8OL'></tbody>

                  <small id='sR8OL'></small><noframes id='sR8OL'>

                    1. <i id='sR8OL'><tr id='sR8OL'><dt id='sR8OL'><q id='sR8OL'><span id='sR8OL'><b id='sR8OL'><form id='sR8OL'><ins id='sR8OL'></ins><ul id='sR8OL'></ul><sub id='sR8OL'></sub></form><legend id='sR8OL'></legend><bdo id='sR8OL'><pre id='sR8OL'><center id='sR8OL'></center></pre></bdo></b><th id='sR8OL'></th></span></q></dt></tr></i><div id='sR8OL'><tfoot id='sR8OL'></tfoot><dl id='sR8OL'><fieldset id='sR8OL'></fieldset></dl></div>
                        <bdo id='sR8OL'></bdo><ul id='sR8OL'></ul>
                      • <legend id='sR8OL'><style id='sR8OL'><dir id='sR8OL'><q id='sR8OL'></q></dir></style></legend>