Url Rewriting - Some advice please? :-)

Last post 06-29-2009 1:08 PM by jamesqua. 3 replies.

Sort Posts:

  • Url Rewriting - Some advice please? :-)

    06-29-2009, 9:19 AM
    • Member
      16 point Member
    • scooner
    • Member since 07-04-2006, 2:52 PM
    • Posts 112

    Hi All,

    I was just wondering whether somebody could point me in the right direction.

    I've developed a solcial networking website that uses profiles. I am wanting users to choose a nickname that can be used to access their profile.

    e.g. www.website-address-here.co.uk/nickname-here

    rather than having www.website-address-here.co.uk/Profile.aspx?profileID=xxx etc.

    What would be the best way to achieve this? I'm not sure which would be the best solution.

    Any advice would be great,

    thanks very much,

    Scott.

  • Re: Url Rewriting - Some advice please? :-)

    06-29-2009, 9:39 AM
    • Star
      7,879 point Star
    • jamesqua
    • Member since 08-03-2004, 2:55 PM
    • Columbus, OH
    • Posts 1,362

    Using the global.asax is a pretty straightforward way to do this.  Here is an example.  http://www.csharpfriends.com/Articles/getTip.aspx?articleID=215

    Josh Harrison
    Community Coder
  • Re: Url Rewriting - Some advice please? :-)

    06-29-2009, 11:08 AM
    • Member
      16 point Member
    • scooner
    • Member since 07-04-2006, 2:52 PM
    • Posts 112

    HI,

    THanks for the link - it makes sense, however when I convert the code to VB i get an error on the word path on the line "Path.GetFileNameWithoutExtension(strCurrentPath)" - it says that "name path is not declared" should it be a different word?

    does that make sense or am i just doing something stupid?

    Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
           
            Dim strCurrentPath As String
            Dim strCustomPath As String
            strCurrentPath = Request.Path
            strCurrentPath = strCurrentPath.ToLower()
            ' the URL contains this folder name

            If strCurrentPath.IndexOf("/SomeSubFolder/") > -1 Then
                strCustomPath = "getContent.aspx?id=" & Path.GetFileNameWithoutExtension(strCurrentPath)
           
                ' rewrite the URL
                Context.RewritePath(strCustomPath)
            End If
        End Sub

    thanks,

    Scott
     

  • Re: Url Rewriting - Some advice please? :-)

    06-29-2009, 1:08 PM
    Answer
    • Star
      7,879 point Star
    • jamesqua
    • Member since 08-03-2004, 2:55 PM
    • Columbus, OH
    • Posts 1,362

    Path is a class in the System.IO namespace so this will work System.IO.Path.GetFileNameWithoutExtension(strCurrentPath)

    Josh Harrison
    Community Coder
Page 1 of 1 (4 items)