从request.querystring中删除字符

时间:2014-08-01 17:37:25

标签: c# javascript asp.net request.querystring

我有一些代码从下面的URL获取DrawingId:

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

我的问题是在运行程序的另一部分之后,该URL变为:

/Queue/Queue.aspx?Mode=Autosearch&DrawingID=188320?DrawingRequestId=376333&doQuerySearch=true&start=&end=&Ind=&Model=&status=Open&manager=&源=安培;受让人=安培;标题=安培;特征=安培;份数=安培; PAS =安培;顾客=安培;数=安培;项目=安培;的startIndex = 1&安培; endIndex的= 10安培;的pageSize = 10安培;总数= 193安培;日期=扩展&安培; qsEnd =

188320之后是否有一个好方法可以删除所有内容?还有一个很好的方法来提取376333的DrawingRequestId吗?

以下是DrawingID的代码:

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

这部分不会运行,因为DrawingId变得不正确:

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

此代码不起作用,因为而不是DrawingId只是188320,

它变为188320?DrawingRequestId = 376333

以下是我认为问题正在开始的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;
            }
        }
    }

1 个答案:

答案 0 :(得分:1)

要删除附加到网址的所有代码,您可以执行以下操作:

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"

要提取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