【发布时间】:2014-08-01 17:37:24
【问题描述】:
我有一些代码可以从下面的 url 中获取 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&endIndex=10&pageSize=10&total=193&date=Extended&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;
}
}
}
【问题讨论】:
-
正则表达式。这将解决您的两个问题。 msdn.microsoft.com/en-us/library/hs600312(v=vs.110).aspx
-
@sparkysword 现在你遇到了三个问题 ;-)
-
哈!是的,@Ted。我主要是指从字符串中提取并在特定字符集之后删除。
标签: c# javascript asp.net request.querystring