Copied to clipboard

Flag this post as spam?

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


  • Tobias Klika 101 posts 570 karma points c-trib
    Jan 27, 2015 @ 16:56
    Tobias Klika
    0

    Process URL with file extension with Umbraco

    Hi!

    I want to dynamically create PDFs per request.
    I have my ContentFinder where I redirect incoming requests (like: ~/pdf/mypdf.pdf) to a site which can process the path, create the PDF and return it to the browser.

    Sadly it does only work for ~/pdf/mypdf (without extension) as Umbraco doesn't handle such file requests.

    How is this possible?

    1. I don't want Umbraco to handle all PDFs, just these under a certain path.
    2. The path is an actual node (in the example ~/pdf/) which can change, you know ;)

    Thanks, Bye Tobi

  • Dan Lister 416 posts 1974 karma points c-trib
    Jan 27, 2015 @ 17:01
    Dan Lister
    100

    Hi Tobias,

    You might be best off creating a HttpHandler rather than creating an Umbraco Content Finder. The advantage of this would be that you get full control of the URLs you want to handle. For example, /pdf/mypdf. You can still get access to all the Umbraco APIs in your HttpHandler when processing a request.

    Hope that helps.

    Thanks, Dan.

  • Tobias Klika 101 posts 570 karma points c-trib
    Jan 27, 2015 @ 17:36
    Tobias Klika
    0

    That's exactly what I was searching for. Thanks so much!

  • Dan Lister 416 posts 1974 karma points c-trib
    Jan 27, 2015 @ 17:37
    Dan Lister
    0

    Awesome! Glad I could help :) Thanks Tobi.

  • Nandoh 32 posts 104 karma points
    Feb 20, 2015 @ 12:05
    Nandoh
    0

    @Dan - Maybe you could answer me to the following questions about this topic's subject:

    1) after a look at the Umbraco's source code, I think that requests like "/media/1001/1234.jpg" are not routed to the Umbraco Request pipeline. Am I correct? If yes, this means that implementations for the interface IContentFinder only works for the "content" items/nodes, right? Is there any way to "handle" requests for "/media/*"path?

    2) suppose that I have a ContentFinder (404ContentFinder : IContentFinder) that returns a content node with a custom template for the "page not found" responses and, like you said to Tobias, I have created a HttpHandler for a specific path (like "/media/*"). Within the HttpHandler I want to return the content node that is returned by the 404ContentFinder. How can I achieve my goal? Should I "repeat" the logic for the 404ContentFinder and use the ContentService to grab that node? (but then...how can I return it in the HttpResponse?) I know that I can respond with a Redirect to that "404" node (or to an unexisting node so it is "catched" by the 404ContentFinder), but I was wondering if I could do that without any redirect because I was trying to render the "page not found" without changing the URL location in the browser...

     

    Thanks in advance ;)

     

  • Tobias Klika 101 posts 570 karma points c-trib
    Feb 20, 2015 @ 18:35
    Tobias Klika
    0

    Hi Nandoh.

    I hope you allow me to answer too ;-)

    1) This is also possible, yes. You can achieve it with the HttpHandler as I did for my PDFs. I did use the following configuration in my web.config (project name altered):

    <httpHandlers>
      ...
      <add verb="GET" path="pdf/*" type="MyProj.MyHttpHandler, MyProj" />
    </httpHandlers>
    

    But one question: Why oh why would you want to do this??

    2) You can easily set a custom 404 page in the umbracoSettings.config. If you want to complete your request in the HttpHandler with 404 you can do it with:

    HttpStatusCodeResult result = new HttpStatusCodeResult(HttpStatusCode.NotFound);
    HttpContext.Current.Response.StatusCode = result.StatusCode;
    HttpContext.Current.Response.Flush();
    HttpContext.Current.Response.End();
    
  • Nandoh 32 posts 104 karma points
    Feb 20, 2015 @ 19:23
    Nandoh
    0

    Hi Tobias,

    Thanks for answering too ;-)

    1) Yes, I took that approach (using a HttpHandler) :) however, the purpose of my question was also to know if requests to the "/media/*" path can (somehow) follow the Umbraco Request Pipeline flow (which means I can create a custom ContentFinder and apply some logic before "serving" the request)

    But one question: Why oh why would you want to do this??

    Suppose that I want to block access (in some cases) to some specific media files, uploaded at backoffice... ;-)

    2) Thanks, I forgot about setting a custom 404 page in the umbracoSettings.config. I'll take a look at it and find if that's enough for what I want. However I think that in umbracoSettings.config we're limited to the node ID to set this up, whereas within the ContentFinder we can search for ID, document type, etc... right?

Please Sign in or register to post replies

Write your reply to:

Draft