如何识别该用户在url中多次发送相同的查询字符串 [英] How to identify that user send same querystring more than once in url

查看:71
本文介绍了如何识别该用户在url中多次发送相同的查询字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的示例网站页面。我将此网址(Api)发给其他人:



http:// localhost:someport / Test.aspx?name = pinky& SId = 123& PhoneNo = XXXX



在这个页面中,我像这样的qurystring成功了



Here is my sample website page.I am giving this url(Api) to others :

http://localhost:someport/Test.aspx?name=pinky&SId=123&PhoneNo=XXXX

In this page I amaccessing qurystring like this

if (Request.QueryString["name"] != null)
{
   Name = Request.QueryString["name"].ToString();                               
}





其他人可以通过他们的软件向我的页面发出请求/呼叫。有时他们可以通过相同的查询字符串两次以上。喜欢这个





Others can make request/call my page from their software.Some time they can pass same querystring more than twice.Like this

http://localhost:someport/Test.aspx?name=pinky&SId=123&PhoneNo=XXXX&SId=43





在我的页面中





In my page

String SId = "";
 if (Request.QueryString["SId"] != null)
    {
       SId= Request.QueryString["SId"].ToString();                               
    }

SId= "123,43";   





如果SId像这样整个我的逻辑改变/失败。我不想这样。如果相同的查询字符串不止一个,应该显示消息。



1>如何识别查询字符串是否出现多次。 2 - ;如果用户传递name = pinky& rani,我的页面只会选择小指。



如何处理这两个?



我尝试过:





If SId come like this entire my logic changes/fails.I don't want like this.If Same querystring come more than one,should show message.

1> How to identify if querystring present more than once. 2> If user pass name=pinky&rani,my page picks up only pinky.

How to handle both?

What I have tried:

String SId = "";
 if (Request.QueryString["SId"] != null)
    {
       SId= Request.QueryString["SId"].ToString();                               
    }

SId= "123,43"; 

推荐答案

检查发布的值的数量,而不是检查可能合法显示在值中的特殊字符:

Rather than checking for special characters, which could legitimately appear within the value, check the number of values posted:
string[] ids = Request.QueryString.GetValues("SId");
if (ids == null)
{
    // The user didn't provide any values for the "SId" parameter.
}
else if (ids.Count != 1)
{
    // The user provided more than one value for the "SId" parameter.
}
else
{
    SId = ids[0];
}


试试这个

try this
string queryString = Request.QueryString.ToString();
         bool isMoreThan1 = queryString.Split(new string[] { "SId=" }, StringSplitOptions.RemoveEmptyEntries).Length > 1;


当一个值出现多次时,当你请求它时,它是逗号分隔的,所以只需查找逗号



When a value appears more than once, when you request it it is comma separated so just look for the comma

if (Request.QueryString["id"].IndexOf(',') != -1)
{
    // show message
}


这篇关于如何识别该用户在url中多次发送相同的查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆