-1

Lets say i have a url- myurl.com/something

I want it to hit at home controller and want to retrieve the last part "something". Something will be dynamic.

Is there any way to do it?

s.k.paul
  • 7,099
  • 28
  • 93
  • 168
  • 2
    Possible duplicate of [Multiple levels in MVC custom routing](http://stackoverflow.com/questions/31934144/multiple-levels-in-mvc-custom-routing) – NightOwl888 Feb 01 '17 at 18:13

1 Answers1

0

Are you trying to do that for many URLS? If it's not something for lots of URLs you could get away redirecting from the BeginRequest or EndRequest functions in the Global.asax.

I once did this in VB.NET (probably easy to get it done in C# as well)

Dim context = New HttpContextWrapper(HttpContext.Current)
Dim rd As RouteData = RouteTable.Routes.GetRouteData(context)
If rd IsNot Nothing Then
Try
    If rd.GetRequiredString("controller") IsNot Nothing Then
        Dim _controller As String = rd.GetRequiredString("controller").ToLower
        Dim _action As String = rd.GetRequiredString("action").ToLower

        Dim cond1 As Boolean = _controller = "home" And _action = "index"

        If cond1 Then
            __DO SOMETHING__
        End If
    End If
Catch ex As Exception

End Try
End If
Kennyomar
  • 107
  • 1
  • 7