How To Parse A URL into sections in ASP.NET Using Pattern Matching

I am trying to find a way to parse a URL in the Global.asax file in ASP.NET into sections.

Given the example of: I need to find a way to capture the PageKey (maybe using a regular expression) in these scenarios:
The folder Pages exists in the URL string followed by some value –
PageKey from the following (trailing slash)
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

SiliconXPConnect With a Mentor Commented:

try this.
string pageKey=string.Empty;
			string str=@"";
			if(str.EndsWith("/")) str=str.Remove(str.Length-1,1);

Open in new window

rajeeshmcaConnect With a Mentor Commented:
hi endrec,

Try the following :

aspx page

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="" >
<head runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript" src="scripts/jquery-1.3.2.js" ></script>
    <script type="text/javascript" src="scripts/jquery.timeentry.js" ></script>
    <script type="text/javascript">
        $(function () {
            $('#TimeTextbox').timeEntry({spinnerImage: ''});
    <form id="form1" runat="server">
    <asp:TextBox ID="TimeTextbox" runat="server"></asp:TextBox>
     <asp:TextBox ID="StringTextBox" runat="server"></asp:TextBox>
     <asp:Button ID="Button1" runat="server" Text="Test" OnClick="Button1_Click" />

cs page

protected void Page_Load(object sender, EventArgs e)

    protected void Button1_Click(object sender, EventArgs e)
        string pageKey = string.Empty;
        pageKey = StringTextBox.Text.Substring(StringTextBox.Text.IndexOf("PageKey", StringComparison.OrdinalIgnoreCase));
        if(pageKey.IndexOf("/") != -1)
            pageKey = pageKey.Substring(0, pageKey.IndexOf("/"));
All Courses

From novice to tech pro — start learning today.