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?
I don't want Umbraco to handle all PDFs, just these under a certain path.
The path is an actual node (in the example ~/pdf/) which can change, you know ;)
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.
@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...
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):
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();
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?
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?
~/pdf/
) which can change, you know ;)Thanks, Bye Tobi
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.
That's exactly what I was searching for. Thanks so much!
Awesome! Glad I could help :) Thanks Tobi.
@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 ;)
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):
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:
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?
is working on a reply...