2016-06-07 2 views
1

URL umbraco MVC 맞춤 경로에서 점을 사용하는 데 문제가 있습니다. /logo/images/image.jpg?width=100는 다음과 같은 오류가 있습니다 :umbraco URL에 점을 사용하는 MVC 맞춤 경로

[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

작품을, 그러나 이것은 좋지 않다 나를위한 해결책. 나는 https://average-joe.info/allow-dots-in-url-iis/ 에서 촬영 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> 

이 추가 시도했지만 작동하지 않습니다 :(

내 사용자 정의 경로는 다음과 같습니다 umbraco

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 사용 vs.7.4.3

+0

예제 URL은 .jpg 파일 확장자를위한 것이며, Umbraco는 동적 크기 조정 이미지를 처리하고 요구 사항에 적합 할 수있는 ImageProcessor에 대한 종속성을 포함하고 있습니까? – Anth12

+0

예 이미 imagecontroller에서 ImageProcessor를 사용하여 사진의 크기를 조정합니다. 사진은 웹 서버 외부에 있으며 크기 조정을 ImageResize.NET과 유사하게 사용하고 싶습니다. 끝 부분에 점을 사용하는 것을 허용하지 않는 라우팅을 제외하고는 해당 코드가 작동합니다. –

답변

0

UmbracoModule ignores Urls with a file extension이므로 UmbracoContext는 요청에 대해 결코 생성되지 않습니다. t 파일 확장명을 포함합니다.

UmbracoContext.EnsureContext를 사용하여 컨텍스트를 만들 수 있지만 처리기의 FindContent 메서드에서이 작업을 수행하면이 예외가 발생합니다. null UmbracoContext에 대한 참조를 보유하고있는 UmbracoVirtualNodeRouteHandler의 line 18에있는 부실 변수로 인해 발생하며 새로 생성 된 컨텍스트를 선택하지 않습니다.

다음은 VirtualNodeRouteHandler가 호출되기 전에 EnsureContext를 호출 할 수있는 방법입니다.

var route = routes.MapRoute("RouteName", "some/url/file.ext", new 
{ 
    controller = "MyController", 
    action = "Index" 
} 
route.RouteHandler = new UrlWithExtensionHandler(); 

공지는하지 MapUmbracoRoute하지만 표준 MVC지도 경로지도, 그리고 UmbracoVirtualNodeRouteHandler의 인스턴스를 반환하기 전에 EnsureContext를 호출하는 표준 MVC IRouteHandler.

public class UrlWithExtensionHandler : IRouteHandler 
{ 
    #region Implementation of IRouteHandler 

    public IHttpHandler GetHttpHandler(RequestContext requestContext) 
    { 
     // init umbraco context 
     var httpContext = new HttpContextWrapper(HttpContext.Current); 

     UmbracoContext.EnsureContext(
      httpContext, 
      ApplicationContext.Current, 
      new WebSecurity(httpContext, ApplicationContext.Current), 
      UmbracoConfig.For.UmbracoSettings(), 
      UrlProviderResolver.Current.Providers, 
      false); 

     var handler = new UrlWithExtensionVirtualNodeRouteHandler(); 
     return handler.GetHttpHandler(requestContext); 
    } 

    #endregion 
} 

public class UrlWithExtensionVirtualNodeRouteHandler : UmbracoVirtualNodeRouteHandler 
{ 
    protected override IPublishedContent FindContent(RequestContext requestContext, 
      UmbracoContext umbracoContext) 
    { 
     return someIPublishedContent; 
    } 
} 

하지 이상적인 솔루션,하지만 오래된 변수 문제까지 유효한 해결 방법은 코어에 통합됩니다 - 나는 몇 가지 다른 사람도 같은 문제 http://issues.umbraco.org/issue/U4-9384

있었다 그것을

를 해결하기 위해 홍보를 제출 한