【问题标题】:How to insert a parameter from my application into an external url如何将我的应用程序中的参数插入外部 url
【发布时间】:2019-03-23 07:39:45
【问题描述】:

我们有一个网站,当插入用户的代码时,它会显示该用户的位置

我有一个示例网址:

http://npaa1215.example.com/gisb_prod/integration/coordUser.aspx?codUser=30071665&zoom=15

我的想法是在我的应用程序中使用此 URL,并将我的应用程序中的用户代码传递给此 URL

如何在请求 "codUser"

的 URL 部分插入来自我的应用程序的参数

在示例中,它使用 "codUser=30071665"

指向用户

有人有想法或例子吗?

【问题讨论】:

标签: c# asp.net .net asp.net-mvc visual-studio


【解决方案1】:

我建议你这个简单的解决方案

string COD_USER="30071665";
Response.Redirect("http://npaa1215.example.com/gisb_prod/integration/coordUser.aspx?codUser="+COD_USER+"&zoom=15");

希望对你有帮助

【讨论】:

    【解决方案2】:

    也许更简单的方法是使用 `HttpUtility.ParseQueryString

    string myUrl = "http://npaa1215.example.com/gisb_prod/integration/coordUser.aspx?zoom=15";
    var uriBuilder = new UriBuilder(myUrl);
    var query = HttpUtility.ParseQueryString(uriBuilder.Query);
    query["COD_USER"] = "30071665";
    query["ANOTHER_QUERY_PARAMETER"] = "ParameterValue";
    uriBuilder.Query = query.ToString();
    myUrl = uriBuilder.ToString();
    

    您可以尝试使用它,基本上,您可以使用ParseQueryString 方法,您可以使用query["COD_USER"] = "30071665" 或您想要的任何其他键添加。

    【讨论】:

      【解决方案3】:

      这是我解决问题的方法:

      控制器:

      [HttpGet]
      public RedirectResult RedirectTo(int id)
      {
      string location = GetLocation(id);
        return RedirectPermanent(location);
      }
      
      string url = "http://npaa1215.example.com/gisb_prod/integration /coordUser.aspx?codUser={0}&zoom=15";
      private string GetLocation(int id)
      {
        return string.Format(url, id);
      }
      

      查看

      href="@Url.Action("RedirectTo","Barcos", new { id = item.SapId })" class="btn btn-danger">
      <span title="Excluir" class="glyphicon glyphicon-alert"></span>
      </a>
      

      【讨论】:

        【解决方案4】:

        下面的代码只是使用 userCode 参数并返回在正确位置插入给定参数的 url:

        string url = http://npaa1215.example.com/gisb_prod/integration/coordUser.aspx?codUser={0}&zoom=15;
        
        private string GetLocation(int userCode) 
        {
          return string.Format(url, userCode);
        }
        

        【讨论】:

        • 添加一些解释,以便每个人都能理解代码。
        • @aloisdg 代码只需使用 userCode 参数并返回在其位置插入给定参数的 url
        猜你喜欢
        • 2011-03-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-12-15
        • 1970-01-01
        • 2019-01-02
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多