How to replace url-parameter?

后端 未结 8 843
谎友^
谎友^ 2021-01-12 01:27

given is an URL like http://localhost:1973/Services.aspx?idProject=10&idService=14.

What is the most straightforward way to replace both url-paramet

8条回答
  •  无人及你
    2021-01-12 01:48

    the C# HttpUtility.ParseQueryString utility will do the heavy lifting for you. You will want to do some more robust null checking in your final version.

        // Let the object fill itself 
        // with the parameters of the current page.
        var qs = System.Web.HttpUtility.ParseQueryString(Request.RawUrl);
    
        // Read a parameter from the QueryString object.
        string value1 = qs["name1"];
    
        // Write a value into the QueryString object.
        qs["name1"] = "This is a value";
    

提交回复
热议问题