Solved

Finding a word in a URL Referrer

Posted on 2011-09-23
3
185 Views
Last Modified: 2012-05-12
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

0
Comment
Question by:vcbertini
3 Comments
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
Split it again on '.'.
0
 
LVL 21

Accepted Solution

by:
Craig Wagner earned 250 total points
Comment Utility
Why not just use the Contains method of the string?

if( itmReferrer.Contains("Freshman")
{
}
else if( itmReferrer.Contains("Transfer")
{
}
0
 

Author Closing Comment

by:vcbertini
Comment Utility
This seemed to be the easiest solution for what I was trying to do. Thanks!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Hangfire / asp.net sample 3 27
SQl help with selection 14 43
Round a string to two digits 12 23
Create XML 5 30
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now