-1

I get my url using Uri like this:

Uri requestUri = Context.Request.Url;

and my url is something like this

http://localhost:1597/Pages/BSC/pe_Rep.aspx?BSCID=27

I want to get only last part of url, I want toi get only digits after sign = so I want to get only value 27 I try to do it using Replace like:

var BSCID = requestUri.Replace("http://localhost:1597/Pages/BSC/pe_Rep.aspx?BSCID=", "");

But is like I can´t use url with Replace, can anyone help me how can I achieve this please?

Ash
  • 5,786
  • 5
  • 22
  • 42
Rafa
  • 19
  • 1
  • Please, try using search before asking question. Here is an answer you are looking for https://stackoverflow.com/questions/14685147/how-can-i-parse-http-urls-in-c – Tamir Nov 23 '17 at 23:15
  • @Rafa, a bit of reading that might help you here: https://en.wikipedia.org/wiki/Query_string and https://www.dotnetperls.com/querystring – Ash Nov 23 '17 at 23:29

1 Answers1

4

String replacement is the wrong way to go about this.

Use the Context.Request.QueryString dictionary to get the value of BSCID.

if (!String.IsNullOrEmpty(Context.Request.QueryString["BSCID"]))
{
    var BSCID = Context.Request.QueryString["BSCID"];
}
SpruceMoose
  • 9,737
  • 4
  • 39
  • 53
Ash
  • 5,786
  • 5
  • 22
  • 42