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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


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

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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("/"));
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.