Click here to Skip to main content
15,918,668 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Ex: sitename/sample.aspx?username=''&userid=''

cs file

string Username = "";
if (Request.QueryString["username"] != null)      
{
    Username = Request.QueryString["username"].ToString();
}
string userid = "";
if (Request.QueryString["userid"] != null)      
{
   userid = Request.QueryString["userid"].ToString();
}

If I use/pass 'username' or 'Username',both get check it is not case sensative.But if user pass like following

Ex: sitename/sample.aspx?username =''&userid=''

I want to restict it.How I check that querystring name contain space?


What I have tried:

string userid = "";
if (Request.QueryString["userid"] != null)      
{
   userid = Request.QueryString["userid"].ToString();
}
Posted
Updated 5-Jan-17 23:38pm

If you are trying to catch any space-only query string, you can always trim the query string to get rid of leading and trailing spaces, then check for its length after trimming, e.g.
string userid = " ";
if(userid.Trim().Length == 0){
     Console.WriteLine("userid is empty");
}
 
Share this answer
 
v2
Might help......... Check with

C#
string username="";
if(!String.IsNullOrEmpty(Request.QueryString["username"]))
{
  username=Request.QueryString["username"];
}
else
{
  Response.Write("Query String is null");
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900