Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1069613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:26:38+00:00 2026-05-16T20:26:38+00:00

I am reading in a number of strings which have / ‘es through them,

  • 0

I am reading in a number of strings which have /‘es through them, the most common example being dates/numbers like 05/06, 07/08, etc.

I am using ASP.NET MVC2 and generating links off of these strings read out of DB, which therein lies the problem.

Obviously a link to:

www.mysite.com/yearperiod/05/06/detail

will not work the same as a link to

www.mysite.com/yearperiod/2005/detail

What is a good solution to this problem? My first thought is to convert every / to a - but then I run into the problem/overhead of having to keep track of which ones were converted, so that when writing back to the DB I don’t inadvertantly switch a valid - to a / (if that makes sense)

edit: come to think of it, I wouldn’t know how to keep track of each converted / … hmmmm…..

edit1: Given this string: “2001/2 – Fruit”

var encodedLinkText = HttpContext.Current.Server.UrlEncode(linkText); //result is "2001%2f2+-+Fruit"

but then if I call that linkhelper from my view the rendered link comes out as :
view source:
<li><a href="2001%2f2+-+Fruit">2001/2 - Fruit</a></li>
rendered link:
http://localhost:XXXX/Period/2001/2+-+Fruit

while I need it as:

http://localhost:XXXX/Period/2001%2f2+-+Fruit

edit2: The browser (testing in chrome) is automatically converting the %2f to a / . What now?

edit3: uh oh… looks like IE behaves properly (as required)… hmmm…

  • IE displays the link properly (encoded) and after clicking it remains encoded.
  • Firefox displays the link decoded and after clicking is encoded.
  • Chrome displays link decoded and after clicking is decoded.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T20:26:38+00:00Added an answer on May 16, 2026 at 8:26 pm

    If your entity in your database is outputting the string ’05/06′ that entity must also have some sort of unique identifier, such as a primary key integer. Couldn’t you include that as part of the URL so your above example becomes:

    www.mysite.com/yearperiod/123/05-06/detail
    

    Then you can convert your slashes to dashes to your hearts content without worrying about converting them back, because the actual database look-up is performed in the ID number (the ‘123’ part) and not the date string.

    If you look at StackOverflow’s URLs they do something similar:

    stackoverflow.com/questions/3648634/dealing-with-es-in-links
    

    3648634 is the database ID for this question which is used to perform the look-up, the ‘dealing-with-es-in-links‘ part is merely there for user friendly descriptive URLs and Search Engine Optimisation.

    Here’s a ToFriendlyUrl() method that can generate these nice looking, SO style, URLs without having to resort to URL Encoding which can make URLs look ugly:

    public static class UrlEncoder 
    { 
        public static string ToFriendlyUrl (this UrlHelper helper, 
            string urlToEncode) 
        { 
            urlToEncode = (urlToEncode ?? "").Trim().ToLower(); 
    
            StringBuilder url = new StringBuilder(); 
    
            foreach (char ch in urlToEncode) 
            { 
                switch (ch) 
                { 
                    case ' ': 
                        url.Append('-'); 
                        break; 
                    case '&': 
                        url.Append("and"); 
                        break; 
                    case '\'': 
                        break; 
                    default: 
                        if ((ch >= '0' && ch <= '9') || 
                            (ch >= 'a' && ch <= 'z')) 
                        { 
                            url.Append(ch); 
                        } 
                        else 
                        { 
                            url.Append('-'); 
                        } 
                        break; 
                } 
            } 
    
            return url.ToString(); 
        } 
    }
    

    You can tweak the code to deal with other special characters such as &ampersands& , but you should get the general idea. You can use in your view like so:

    <%= Url.ToFriendlyUrl(item.Title) %>
    

    So in a nutshell, don’t relly on UrlEncoding, but use a FriendlyUrl utility like the one above and include the database ID for the actual database look-up.

    I’ve written a blog post in this subject her http://www.dominicpettifer.co.uk/Blog/34/asp-net-mvc-and-clean-seo-friendly-urls

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a BAT file, which creates a number of csv files by reading
I remember reading an article saying something like The number of bugs introduced doesn't
I am reading a text file which contains numbers in the range [1, 10^100].
So I have an example I came across in some reading where we define
I have a TV Guide activity which extends TabActivity. The tabs are labelled (example)...
I have a Plist in which I have a number of Array's. Within these
I have a class called ItemBase from which a number of classes inherit. In
I've got a number of classes which have a relationship to other classes for
I have a C++ script which involves string representations of would-be hexadecimal numbers. In
If I have a definition which is only repeated strings, I can find the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.