• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 282
  • Last Modified:

Page Routing or Redirection...

I have a situation.

I find myself needing to redirect any request that contains the path '/Sites/' to '/Sites/' & VariableID

For example:

needs to become

note, there are many folders inside /Sites/SITEID123456 that can contain anything from .exe to .jpg, to even fonts... so I need a wildcard solution

I thought I would be able to do this with .MapPageRoute, however, the more I read up on it, the more it seems I can only route to a page

How can I do this then?
(.Net 4, I am using VB, but I can translate a C# solution...)
  • 4
1 Solution
I think you can just setup a custom route in your global.asax file.  This link may help.

kevp75Author Commented:
sorry.  this is non-mvc...
kevp75Author Commented:
got it.

In global.asax:
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
        ' Fires at the beginning of each request
        Dim app As HttpApplication = TryCast(sender, HttpApplication)
        Dim _Path As String = app.Request.Path
        If _Path.ToLower.Contains("sites/") Then
            app.Context.RewritePath(_Path.Replace("Sites/", "Sites/" & Settings.SiteID & "/"))
        End If
    End Sub

Open in new window

kevp75Author Commented:
anyone got anything better?  otherwise I'm gonna roll with it...
kevp75Author Commented:
answered it myself
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now