简体   繁体   English

从request.querystring中删除字符

[英]Remove characters from request.querystring

I have some code which gets the DrawingId from an url like the one below: 我有一些代码从类似下面的网址中获取DrawingId:

/Queue/Queue.aspx?Mode=Autosearch&DrawingID=188320" /Queue/Queue.aspx?Mode=Autosearch&DrawingID=188320"

My issue is after running another part of the program, that url becomes this: 我的问题是在运行程序的另一部分后,该网址变成了:

/Queue/Queue.aspx?Mode=Autosearch&DrawingID=188320?DrawingRequestId=376333&doQuerySearch=true&start=&end=&Ind=&Model=&status=Open&manager=&source=&assignee=&title=&features=&parts=&pas=&customer=&number=&project=&startIndex=1&endIndex=10&pageSize=10&total=193&date=Extended&qsEnd= /Queue/Queue.aspx?Mode=Autosearch&DrawingID=188320?DrawingRequestId=376333&doQuerySearch=true&start=&end=&Ind=&Model=&status=Open&manager=&source=&assignee=&title=&features=&parts=&pas=&customer=&number=&project=&startIndex=1&endIndex = 10&的pageSize = 10&总= 193&日期=扩展&qsEnd =

Is there a good way remove everything after 188320? 有什么好方法可以删除188320之后的所有内容? Also is there a good way to extract the DrawingRequestId of 376333? 还有没有办法提取376333的DrawingRequestId?

Here is the code for DrawingID: 这是DrawingID的代码:

public string DrawingId
{
  get
  {
   if (Request.QueryString["DrawingID"] != "" && Request.QueryString["DrawingID"] != null)
   {
     return Request.QueryString["DrawingID"];
   }
  return null;
  }
}

This part won't run because the DrawingId becomes incorrect: 这部分将不会运行,因为DrawingId变得不正确:

List<string> featureCodes = drawingBusiness.GetFeatureCodesByDrawingId(long.Parse(DrawingId));

This code doesn't work because instead of DrawingId just being 188320, 该代码不起作用,因为与其将DrawingId设为188320,

it becomes 188320?DrawingRequestId=376333 它变成188320?DrawingRequestId = 376333

Here is the javascript where I assume the problem is starting: 这是我认为问题开始的javascript:

function CloseAndRefresh() {
        var parentUrl = window.top.location.href;
        if (parentUrl.indexOf("Queue/Queue.aspx") != -1) {

            if (window.location.search === "") {
                window.location.href = window.top.location
            }
            else {
                window.top.location.href = window.top.location + window.location.search;
            }
        }
        else {
            if (window.location.search === "") {
                window.location.href = window.top.location
            }
            else {
                window.top.location.href = window.top.location + window.location.search;
            }
        }
    }

To remove all the code appended to your url you can do something like: 要删除附加到您网址中的所有代码,您可以执行以下操作:

var longURL = "/Queue/Queue.aspx?Mode=Autosearch&DrawingID=188320?DrawingRequestId=376333&doQuerySearch=true&start=&end=&Ind=&Model=&status=Open&manager=&source=&assignee=&title=&features=&parts=&pas=&customer=&number=&project=&startIndex=1&endIndex=10&pageSize=10&total=193&date=Extended&qsEnd=";

var shortURL = longURL.split('?').slice(0, -1).join('?');

console.log(shortURL) // "/Queue/Queue.aspx?Mode=Autosearch&DrawingID=188320"

To extract the DrawingRequestId you can do something like: 要提取DrawingRequestId您可以执行以下操作:

var longURL = "/Queue/Queue.aspx?Mode=Autosearch&DrawingID=188320?DrawingRequestId=376333&doQuerySearch=true&start=&end=&Ind=&Model=&status=Open&manager=&source=&assignee=&title=&features=&parts=&pas=&customer=&number=&project=&startIndex=1&endIndex=10&pageSize=10&total=193&date=Extended&qsEnd=";

var drawingRequestId = parseInt(longURL.substr(longURL.indexOf('DrawingRequestId=')+17, 6));

console.log(drawingRequestId) // 376333

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM