I need to have a variable before every controller.
I want something like that: www.mysite.com/SYSTEMVARIABLE/Controller/Action
Example:
www.mysite.com/internalevent/Inscricao/Index
www.mysite.com/externalevent/Inscricao/Index
And i need to get the "internalevent" or "externalevent"
Example of values array At this example, i need the [0] value of array, be the SYSTEMVARIABLE, not "Inscricao (Controller)"
So, how can i get the "SYSTEMVARIABLE" value and work with this ?
I have the following now (not working...)
routes.MapRoute(
name: "Default",
url: "{sistema}/{controller}/{action}/{id}",
defaults: new { controller = "Inscricao", action = "Index", id = UrlParameter.Optional },
constraints: new { sistema = new SistemaRouteConstraint() }
);
I need to get the value from "{sistema}", and i need to do some logic on this value.
Below is the class i want to get it, but ALWAYS the "{sistema}" only gets me the controller value (controller come twice on 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;
}
}