Solved

Finding a word in a URL Referrer

Posted on 2011-09-23
3
190 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 36591520
Split it again on '.'.
0
 
LVL 21

Accepted Solution

by:
Craig Wagner earned 250 total points
ID: 36592430
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
ID: 36599556
This seemed to be the easiest solution for what I was trying to do. Thanks!
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Save json data from URL using SSIS 1 71
C# DateTime Help 6 43
What!!!??? 5 57
C# How to display the first five answers that have smallest value? 16 40
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

736 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