如何识别查询字符串名称是否包含空格

如何识别查询字符串名称是否包含空格

本文介绍了如何识别查询字符串名称是否包含空格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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();
}

推荐答案

string userid = " ";
if(userid.Trim().Length == 0){
     Console.WriteLine("userid is empty");
}


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


这篇关于如何识别查询字符串名称是否包含空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-17 09:07