Asp.net

如何在 OnActionExecuting 中獲取目前路由資訊

  • October 24, 2017

我的網址如下所示:

www.example.com/{languagecode}/{controller}/{action}/{id}

其中語言程式碼為 en-us 等。

從 OnActionExecuting 事件中,如何獲取這些值?

protected override void OnActionExecuting(System.Web.Mvc.ActionExecutingContext filterContext)
{
   var languagecode = filterContext.RouteData.Values["languagecode"];

   base.OnActionExecuting(filterContext);
}

引用自:https://stackoverflow.com/questions/2967417