Query strings with special characters

后端 未结 3 902
醉梦人生
醉梦人生 2020-12-07 03:14

How I can pass a query string with special characters?

For example I need to pass \"&\" inside my query string as below:

../solrresults.asp?mode=         


        
3条回答
  •  感动是毒
    2020-12-07 04:02

    As stated, the UrlEncode method would be the way to go.

    Some time ago I wrote a small class QueryString to simplify the work with those query strings.

    An example usage would be:

    private void Page_Load(
        object sender, 
        System.EventArgs e )
    {
        // Let the object fill itself 
        // with the parameters of the current page.
        QueryString qs = new QueryString();
    
        // Read a parameter from the QueryString object.
        string value1 = qs["name1"];
    
        // Now remove the parameter.
        qs.RemoveParameter( "name1" );
    
        // This has the same effect as RemoveParameter() method:
        qs["name1"] = null;
    
        // ... Further processing of the value1 variable ... 
    }
    

    You can fill the query string class and don't have to care whether to URL-encode the values, the class handles this internally for you.

提交回复
热议问题