How to check that Request.QueryString has a specific value or not in ASP.NET?

前端 未结 8 1276
孤街浪徒
孤街浪徒 2020-12-08 06:12

I have an error.aspx page. If a user comes to that page then it will fetch the error path in page_load() method URL using Request.QueryStrin

8条回答
  •  -上瘾入骨i
    2020-12-08 06:46

    To resolve your problem, write the following line on your page's Page_Load method.

    if (String.IsNullOrEmpty(Request.QueryString["aspxerrorpath"])) return;
    

    .Net 4.0 provides more closer look to null, empty or whitespace strings, use it as shown in the following line:

    if(string.IsNullOrWhiteSpace(Request.QueryString["aspxerrorpath"])) return;
    

    This will not run your next statements (your business logics) if query string does not have aspxerrorpath.

提交回复
热议问题