2016-01-08 141 views
0

我想檢查url是否具有查詢字符串值?或不。如何檢查url是否包含查詢字符串

如果查詢字符串值不存在,如果它是一個普通的URL,它應該重定向至其他網頁,因此,如果有人直接訪問網頁,他們應該被重定向至其他網頁

protected void Page_Load(object sender, EventArgs e) 
{ 
    if (string.IsNullOrWhiteSpace(Request.QueryString["aspxerrorpath"])) 
    { 
     uniqueid = Request.QueryString["val"]; 
    } 
    else 
    { 
     Response.Redirect("proformainvoice.aspx"); 
    } 

    if (!Page.IsPostBack) 
    { 
     fillproformadata(); 
    } 
} 
+0

NameValueCollection qscoll = HttpUtility.ParseQueryString(Request.QueryString); –

+0

給錯誤 - 無法從「System.Collections.Specialized.NameValueCollection」到「字符串」 –

+0

嘗試轉換把VAR代替的NameValueCollection qscoll –

回答

1

你可以使用HasKeys方法Request.QueryString檢查url是否包含QueryString

bool hasKeys = Request.QueryString.HasKeys(); 
if(hasKeys) 
{ 
//your code  
} 
else 
{ 
//your code 
} 
相關問題