Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7184789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:16:25+00:00 2026-05-28T18:16:25+00:00

I have implemented a custom route (inherit from RouteBase) to have dynamic routes based

  • 0

I have implemented a custom route (inherit from RouteBase) to have dynamic routes based on the data stored in the database. After processing, this route ends up returning RouteData containing
1) An EF entity
2) action
3) controller

All works as expected except that I would like for the controller value to be either the full type name of a controller (I allow my users to select it from the admin panel) or the word ‘Auto’. If Auto is selected I use structure map to locate a controller that implements a generic Controller<TEntityType>. To do this I return with the route data an MvcRouteHandler with a custom controller factory passed into it’s constructor.

After a little digging I realized that the MvcRouteHandler does not pass that controller factory to the MvcHandler that it creates therefore my custom controller factory is never called and the route always fails.
I am not sure what alternatives I have if any. I think I could probably set the controller factory in general but I feel that that would be wrong as only the requests handled by my custom routes should have the custom controller factory.

Thanks in advance,
John

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T18:16:27+00:00Added an answer on May 28, 2026 at 6:16 pm

    In the end the following works. The only gray point is the ReleaseController method to which the framework does not pass a RequestContext. This is ok though because all that method does is call dispose on the controller if it implements IDisposible so the default implementation is fine.

       public class RouteControllerFactory : IControllerFactory
    {
        private readonly DefaultControllerFactory Default = new DefaultControllerFactory();
    
        public IController CreateController(System.Web.Routing.RequestContext requestContext, string controllerName)
        {
            return (requestContext.RouteData.Values.TryGetValue("controllerfactory") as IControllerFactory ?? Default).CreateController(requestContext, controllerName);
        }
    
        public System.Web.SessionState.SessionStateBehavior GetControllerSessionBehavior(System.Web.Routing.RequestContext requestContext, string controllerName)
        {
            return (requestContext.RouteData.Values.TryGetValue("controllerfactory") as IControllerFactory ?? Default).GetControllerSessionBehavior(requestContext, controllerName);
        }
    
        public void ReleaseController(IController controller)
        {
            Default.ReleaseController(controller);
        }
    }
    

    To register the controller factory just use
    ControllerBuilder.Current.SetControllerFactory(typeof(RouteControllerFactory));

    at Application_Start

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have implemented a custom ActionMapper which obtains the locale from the URI (the
In my WCF service I have implemented a custom encoder which inherits from System.ServiceModel.Channels.MessageEncoder
I have implemented a custom trace listener (derived from TextWriteTraceListener ) and now I
I have implemented my custom drag&drop by deriving from COleDataSource and COleDropTarget. Everythings work
I have implemented my own custom Authorization Attribute in MVC 4 by inheriting from
My problem is that I have implemented a custom arrayadapter, that fetches images from
I have successfully implemented a custom SimpleCursorAdapter for an AutoCompleteTextView, which suggests entries from
So, I have implemented custom routing in mysite. routes.MapRoute( WithFriendlyNameOnly, {friendlyName}, new { controller
I have implemented a custom view within another activity into a XML layout. The
I'm using OSMdroid to implement a mapping application. I have implemented a custom MapTileProvider

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.