我需要在每个控制器之前都有一个变量。
我想要这样的东西: www.mysite.com/ 系统变量 /控制器/操作
示例:
www.mysite.com/ 内部事件 / Inscricao / Index
www.mysite.com/ 外部事件 / Inscricao / Index
我需要获取“内部事件”或“外部事件”
Example of values array 在此示例中,我需要数组的[0]值,应为 SYSTEMVARIABLE ,而不是“ Inscricao(控制器)”
那么,我如何获取“ SYSTEMVARIABLE”值并与此配合使用?
我现在有以下内容(无法正常工作...)
routes.MapRoute(
name: "Default",url: "{sistema}/{controller}/{action}/{id}",defaults: new { controller = "Inscricao",action = "Index",id = UrlParameter.Optional },constraints: new { sistema = new SistemaRouteConstraint() }
);
我需要从“ {sistema} ”中获取值,并且需要对此值进行一些逻辑处理。
下面是我要获取的类,但始终“ {sistema} ”仅为我获取控制器值(控制器在RouteValueDictionary上出现两次)
public class SistemaRouteConstraint : IRouteConstraint
{
public bool Match(HttpContextBase httpContext,Route route,string parameterName,RouteValueDictionary values,RouteDirection routeDirection)
{
object sistema;
if(values.TryGetvalue(parameterName,out sistema) && values != null)
{
var NomeSistema = values["sistema"].ToString();
using (Entities db = new Entities())
{
/*some logic here*/
}
}
return true;
}
}