Click here to Skip to main content
15,892,575 members
Articles / Web Development / ASP.NET

Solution for URL Rewriting in ASP.NET

Rate me:
Please Sign up or sign in to vote.
4.24/5 (13 votes)
3 Jul 2007CPOL8 min read 110.1K   803   69  
Powerful solution for URL rewriting and handling rewritten parameters in ASP.NET.
Namespace Navigation

    Public MustInherit Class NavigationProviderBase

#Region "   MustInherit Methods   "

        Protected MustOverride Sub processNavigation()

#End Region

#Region "   Properties   "

        Private _navigationParts As New Dictionary(Of String, String)
        Friend Property NavigationParts() As Dictionary(Of String, String)
            Get
                Return _navigationParts
            End Get
            Set(ByVal value As Dictionary(Of String, String))
                _navigationParts = value
            End Set
        End Property

        Private _querystringParts As New Dictionary(Of String, Object)
        Friend Property QuerystringParts() As Dictionary(Of String, Object)
            Get
                Return _querystringParts
            End Get
            Set(ByVal value As Dictionary(Of String, Object))
                _querystringParts = value
            End Set
        End Property

        Private _currentUrl As String
        Public Property CurrentUrl() As String
            Get
                Return _currentUrl
            End Get
            Set(ByVal value As String)
                _currentUrl = value
            End Set
        End Property

#End Region

#Region "   Constructor   "

        Public Sub New()

            Dim querystring As String = String.Empty
            CurrentUrl = HttpContext.Current.Request.RawUrl

            'Remove the domain and querystring information
            If HttpContext.Current.Request.RawUrl.Contains("?") Then
                CurrentUrl = HttpContext.Current.Request.RawUrl.Substring(0, CurrentUrl.IndexOf("?"))
            End If

            'Add the querystring values to the dictionary
            processQuerystring()

        End Sub

#End Region

#Region "   Private Methods   "

        Private Sub processQuerystring()
            'Convert the querstring items to an array
            For Each key As String In HttpContext.Current.Request.QueryString.Keys
                QuerystringParts.Add(key, HttpContext.Current.Request.QueryString(key))
            Next
        End Sub

#End Region

    End Class

End Namespace

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions