Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • goran backlund 1 post 71 karma points
    Jun 07, 2016 @ 09:19
    goran backlund
    0

    umbraco MVC custom routes using a dot in url .

    I have a problem with using a dot in url umbraco MVC custom routes. /logo/images/image.jpg?width=100 gives following errors:

    [NullReferenceException: Object reference not set to an instance of an object.]
       Umbraco.Web.Mvc.UmbracoVirtualNodeByIdRouteHandler.FindContent(RequestContext requestContext, UmbracoContext umbracoContext) +18
       Umbraco.Web.Mvc.UmbracoVirtualNodeRouteHandler.GetHttpHandler(RequestContext requestContext) +48
       System.Web.Routing.UrlRoutingModule.PostResolveRequestCache(HttpContextBase context) +11987058
       System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +141
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +91
    

    /logo/images/image.jpg/?width=100

    Works, but this isn’t a good solution for me. I have tried adding this in webconfig

    <location path="logo">
            <!-- This only applies it to the relevant path and keeps the protection in place for elsewhere -->
            <system.web>
                <httpHandlers>
                    <add path="/images/*" type="System.Web.Handlers.TransferRequestHandler" verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" />
                </httpHandlers>
            </system.web>
            <!-- Required for IIS 7.0+ -->
            <system.webServer>
                <modules runAllManagedModulesForAllRequests="true" />
                <validation validateIntegratedModeConfiguration="false" />
                <handlers>
                    <add name="ApiURIs-ISAPI-Integrated-4.0" path="*" type="System.Web.Handlers.TransferRequestHandler" verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" preCondition="integratedMode,runtimeVersionv4.0" />
                </handlers>
            </system.webServer>
        </location>
    

    taken from https://average-joe.info/allow-dots-in-url-iis/ but it won't work:(

    My custom route looks like this:

    protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            //custom route
            RouteTable.Routes.MapUmbracoRoute(
            "images",
            "logo/{action}/{key}",
            new
            {
                controller = "Image",
                key = UrlParameter.Optional,
    
    
    
            },
          new ProductsRouteHandler(4884));
        }
    }
    public class ProductsRouteHandler : UmbracoVirtualNodeByIdRouteHandler
    {
    
        public ProductsRouteHandler(int realNodeId) : base(realNodeId)
        {
        }
    
        protected override IPublishedContent FindContent(RequestContext requestContext, UmbracoContext umbracoContext, IPublishedContent baseContent)
        {
            return base.FindContent(requestContext, umbracoContext, baseContent);
        }
    }
    

    I'am using umbraco vs.7.4.3

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies