Asp.net mvc 在asp.net中检索主域后的任何单词

Asp.net mvc 在asp.net中检索主域后的任何单词,asp.net-mvc,routing,Asp.net Mvc,Routing,假设我有一个url- myurl.com/something 我希望它击中在家控制器,并希望检索最后一部分“东西”。事情将是动态的 有什么方法可以做到这一点吗?对于许多URL,您是否正在尝试这样做?如果这不是很多URL的问题,那么可以从Global.asax中的BeginRequest或EndRequest函数中进行重定向 我曾经在VB.NET中这样做过(在C#中也很容易做到) 可能重复的 Dim context = New HttpContextWrapper(HttpContext.Curr

假设我有一个url- myurl.com/something

我希望它击中在家控制器,并希望检索最后一部分“东西”。事情将是动态的


有什么方法可以做到这一点吗?

对于许多URL,您是否正在尝试这样做?如果这不是很多URL的问题,那么可以从Global.asax中的BeginRequest或EndRequest函数中进行重定向

我曾经在VB.NET中这样做过(在C#中也很容易做到)

可能重复的
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