public override IController CreateController(System.Web.Routing.RequestContext requestContext, string controllerName)
Is it normal that the controllerName passed into this function is sometimes "content"?
how can i avoid that?
public override IController CreateController(System.Web.Routing.RequestContext requestContext, string controllerName)
{
var controllerType = GetControllerType(controllerName);
var projectType = ConfigurationManager.AppSettings["Sales"];
if (controllerType.BaseType == Type.GetType(projectType))
{
var salesid = requestContext.RouteData.Values["salesid"];
int intValue;
int.TryParse(salesid.ToString(), out intValue);
if (intValue == 0)
throw new FormatException("salesid is missing");
return Activator.CreateInstance(controllerType, int.Parse(salesid.ToString())) as IController;
}
return base.CreateController(requestContext, controllerName);
}
The controllerName being passed here is sometimes "Content". I just thought that it should be controller name.