0
public override IController CreateController(System.Web.Routing.RequestContext requestContext, string controllerName)
asp.net mvc重寫DefaultContollerFactory的CreateController?
這是正常的controllerName傳遞到這個功能有時是 「內容」?
我該如何避免這種情況?
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);
}
這裏傳遞的controllerName有時是「Content」。 我只是認爲它應該是控制器名稱。