从request.querystring中删除字符 - c#

我有一些代码从类似下面的网址中获取DrawingId:

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

我的问题是在运行程序的另一部分后,该网址变成了:

/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&end= = 10&pageSize = 10&总计= 193&date =扩展&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;
            }
        }
    }

参考方案

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

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

调用javascript函数&&处理事件 - c#

我有一个asp.net应用程序,当事件被触发时,我必须在其中调用javascript函数。protected Consultation controlconsultation = new Consultation(); protected void Page_Load(object sender, EventArgs e) { controlconsulta…

JVM如何运行if(condition && false)语句? - java

目前,我正在开发一个具有内存密集检查过程的程序。在某些时候,代码看起来像这样。if(isvalid() && false) //this false is acctually another method which will at this given //point always return false { //rest ommited…

在两个值之间匹配并返回正则表达式 - javascript

我正在尝试使用正则表达式从字符串中获取值,该值是tt="和"&之间的文本的值因此,例如,"tt="Value"&"我只想从中得到单词"Value"。到目前为止,我已经有了:/tt=.*&/这给了我"tt=Value"&,然后,要…

当回复有时是一个对象有时是一个数组时,如何在使用改造时解析JSON回复? - java

我正在使用Retrofit来获取JSON答复。这是我实施的一部分-@GET("/api/report/list") Observable<Bills> listBill(@Query("employee_id") String employeeID); 而条例草案类是-public static class…

改造正在返回一个空的响应主体 - java

我正在尝试使用Retrofit和Gson解析一些JSON。但是,我得到的响应机构是空的。当我尝试从对象中打印信息时,出现NullPointerException。我确保URL正确,并且我也确保POJO也正确。我正在使用jsonschema2pojo来帮助创建POJO类。这是我要解析的JSON{ "?xml": { "@versi…