views:

25

answers:

1

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.

A: 

Is it normal that the controllerName passed into this function is sometimes "content"?

Not sure what you mean sometimes. You must have ContentController and when an action of this controller is invoked controller name will be "content"/"Content".

how can i avoid that?

I do not see any reason you need to avoid having name of the controller in controllerName parameter.

Dmytrii Nagirniak

related questions