Link to home
Start Free TrialLog in
Avatar of vcbertini
vcbertiniFlag for United States of America

asked on

Finding a word in a URL Referrer

This seems like it should be so simple, but is proving to be more difficult than I thought. Maybe I'm overanalyzing the problem.  What I need to do is grab the referring URL, look for a specific word in that URL, then perform some actions based on those results.

For some reason, my code is not grabbing the proper word because it has ".aspx" tacked on to the end of it, so for example it's finding "Freshman.aspx" instead of just "Freshman" and then it's not processing the code properly.  What can I do to fix that?
if (HttpContext.Current.Request.UrlReferrer != null)
                {
                    string itmReferrer = HttpContext.Current.Request.UrlReferrer.ToString();
                    words = itmReferrer.Split('/');
                    lblReferrer.Text = itmReferrer;
                }

foreach (string word in words)
                {
                    switch (word)
                    {
                        case "Freshman":
                            rblProgram.SelectedValue = "UG";
                            lblPageTitle.Text = "Freshman Application";
                            break;
                       case "Transfer":
                            bla bla bla
                            break;
                    }
}

Open in new window

Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Split it again on '.'.
ASKER CERTIFIED SOLUTION
Avatar of Craig Wagner
Craig Wagner
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of vcbertini

ASKER

This seemed to be the easiest solution for what I was trying to do. Thanks!