How do you test your Request.QueryString[] variables?

前端 未结 11 2166
梦如初夏
梦如初夏 2020-11-29 16:05

I frequently make use of Request.QueryString[] variables.

In my Page_load I often do things like:

       int id = -1;

             


        
11条回答
  •  野性不改
    2020-11-29 16:29

    I'm using a little helper method:

    public static int QueryString(string paramName, int defaultValue)
    {
        int value;
        if (!int.TryParse(Request.QueryString[paramName], out value))
            return defaultValue;
        return value;
    }
    

    This method allows me to read values from the query string in the following way:

    int id = QueryString("id", 0);
    

提交回复
热议问题