How can I use the Server Side Includes module in IIS to include and process a ColdFusion file from a .htm file? I'm currently doing something like this in my html file:
<!--#include virtual="navmenu.cfm"-->
This includes the raw contents of the navmenu file. I need it to execute the ColdFusion code and return the output of that process rather than including the raw ColdFusion code.
This same syntax works properly in Apache.
Are you just trying to avoid the CFM extension in the URL?
You can't use SSI to include a CFM files into a static HTM file. You can configure IIS to send HTM files to the CF server to be parsed. This would allow you to use CFINCLUDE inside any HTM file.
Alternately, you can use ajax from your HTM file and load the parsed CFM content into a DIV.
If you can't make the top page appear to be a cfm to the outside have you thought about using the URL Rewrite Module for IIS? That way you could just make certain files cfms with some explicit htm to cfm rewrite rules but leave all others unprocessed. Beyond that I think there may not be an elegant answer since you are mixing static and dynamic content.
On your comment about ajax - personally I don't find anything tedious about using ajax but then again jquery spoils you...
<div id='menuhere'></div>
$.get('navmenu.cfm', function(data) {$('.menuhere').html(data); });
Accomplishes the same thing as the SSI plus (assuming jQuery is cached) you get faster main content page loads to boot.
If you are using a Coldfusion page it is:
<cfinclude template="navmenu.cfm">
If you are using another type of page you will need to put that content in an IFRAME
<iframe src="navmenu.cfm"></iframe>
The question is if you have Coldfusion technology available on the server, why not change that page to a .cfm page and use the above example?
Related
Say I have html template https://www.free-css.com/free-css-templates/page244/debut How do I insert them into Drupal correctly so that it works exactly as I if've put these files from archive alongside Drupal...? So that if I open "mysite.com/contact.html" I get exactly the contents of contact.html an everything inside (links to css/js files) works.
If I'm understanding, you want to serve a static HTML file from the same domain as a Drupal site, and not bootstrap Drupal in the process, so the static HTML gets served directly. I'd recommend using the Pathed Files module (https://www.drupal.org/project/pathed_files) which lets you upload a static file or paste its contents into a form, and specify a custom URL for it. Alternatively, if you just put an HTML file in the Drupal files directory (e.g. https://your.website.com/sites/default/files/your-html-file.html), your Web server will happily serve it as is, but you have to live with that /sites/default/files/ path in the URL. Truth be told, you could put it right in the Drupal Web root, alongside index.php, and the Web server will serve it without bootstrapping Drupal. But that's very ugly, and you really, really should not do that.
For whatever reason (ugh, just assume we have to), we have a JavaScript file and a CSS file without an extension in our ASP.NET MVC application. The JavaScript file is at path ~/Scripts/js and the CSS file is at ~/Styles/css. These are static files containing JS and CSS respectively, but without file extensions.
Right now, when I try to load the resources in a browser, I get a 404 for those two paths. What do I need to do to make my ASP.NET MVC application serve these extensionless files (and serve them with the correct MIME types)? Something in the web.config and mapping a particular URL pattern to the HTTP handler for static files, I'm guessing. Apparently my Googling skills are inadequate—forgive me.
I think esmoore68 probably has the best answer... but... if you don't want to do that, I wonder if you could declare the style (and the script) on the page (rather than reference the files), and maybe use labels on the pages where you need these, and actually open the files in code-behind, read them as text, then write them into the labels on the page load?
I haven't tried anything like that, specifically, but it seems like it would work.
If it does, maybe you could create a user control so you can just put that in all the pages, rather than repeating it every time.
Background
I have an ASP.NET Web Forms app that I want to localize using .RESX files. I already know how to do this using .ASPX files. However, my application uses some .ASPX files... as well as some plain .HTML files.
(I am doing a lot of KnockoutJs, where the app retrieves the reusable HTML templates and injects them into the DOM as needed.)
I can't take the following approach in the HTML files, since the <%$ code would not be executed.
<%$ Resources:Main, WelcomeMessage %>
The Question
Is it possible to use C# code to process a plain HTML file against a RESX file to generate an HTML file that has been localized?
(I NEED A SOLUTION WITHOUT USING AN .ASPX FILE)
If this is possible, then I might be able to create a web service that will apply a RESX file to an HTML file and return the resulting HTML string.
Answer
I think the answer.... is No.
There does not seem to be an easy way to do this with ASP.NET Web Forms. So instead I switched my project to use ASP.NET MVC.... where this problem is more readily solved.
In case you are interested... here's what I did in MVC:
I changed the HTML files to .cshtml files (which support syntax that works with .RESX files). I created a controller I call HtmlController with a GetHtml action. The GetHtml method takes a URL as a parameter, and renders the contents of the requested .cshtml file, which is returned as a PartialView.
Now right after my page loads, I can fire Ajax requests to retrieve some shared HTML templates by calling that GetHtml action on HtmlController. The HTML content of my requested .cshtml file is localized against my .RESX file and then returned as the result of my Ajax call. I can then bind it on the page.
This works particularly well for shared HTML templates that I reuse across various pages, but I still need to have them localized for the currently selected Culture.
In retrospect
I still feel moving to MVC was the right decision.
However..... I suppose after having switched to MVC.... it might have been simpler to just directly render partial views (for each of those shared templates) on each page that needs access to them.
Then I could have avoided making separate Ajax calls to pull this stuff down when the page loads.
[FacePalm]
We have legacy code to maintain and, to solve a specific customer customization problem, we want to route calls to some files to other files. That is, when the app calls a particular ASPX, it will end up hitting another ASPX.
If you call:
www.foo.com/admin/admin.aspx
It will actually hit:
www.foo.com/customizations/customer1/admin/admin.aspx
This is not a good design but this is legacy code. We just want to solve this.
We are using the System.Web.Routing framework to solve it. This works fine when you set RouteExistingFiles to true, except for static files (CSS, JavaScript and Images).
When I first tried it, it retrieved this error:
There is no build provider register for the extension '.css'.
So I did register a build provider in the web.config file for the .css extension. I used this build provider: PageBuilderProvider because someone recommended it in the internet.
It works! But the CSS is being served with text\html content type.
How do I achieve this?
TL;DR: I want to use routes in ASP.NET Web Forms to make a call for a specific CSS file to actually retrieve another one. A customer needs this for customization.
Try coding a HttpHandler. I had to do something similar but for PDF files, I coded a custom HttpHandler in the end - works very well. You can even set the content type in the HttpHandler code and have a pattern matched path the handler will be used for in the web.config. You can also configure it in web.config not to execute if the path does not point to an existing file e.g. so a 404 is returned without having to code that in the handler itself. I can't post my code (VB.NET) ATM because I'm using a tablet but google search for tutorials. You will also probably need to use the TransmitFile function to actually write out the css file. Is it a web forms project or web site? If its a web site there is a special way of registering the HttpHandler in the web.config.
I seen an ASP.NET application, in the URL is saying:
http://xxxxxxxxx/FILENAME.html?xxxx=xxx
How come it is html file? But not aspx file? How did they do it?
I heard from my manager that's an ASP.NET project he outsourced.
Sometime I seen people with their web page is ended in .html too, but obviously that is generated dynamically...
Files ending with .html are optional. These are static HTML-pages without any code-behind and can be included as part of any web application. They are not parsed and compiled by the server but rather just sent as good old predefined HTML.
You can also configure the web server so that it routes requests with different endings through the ASP.net rendering engine. This way you can keep the widely recognized ending .html and still have dynamic page generation.
The file extension is not necessarily tied to the execution engine. You can make ASP.NET process .aspx, .html, .htm, .bob, .foobar, .css, etc.
There are multiple of ways to do this:
In IIS manager, set the file extension mapping for .html to point to ASP.NET. If you're using MVC, you can handle this via routing.
Use a rewrite engine to map anything with a .htm* extension to .aspx
There are probably other ways, but these are the most direct.
Also, the .html extension doesn't mean that the file was dynamically generated.
You can use URL rewriting. There are a lot of different rewriters most popular being the URL rewrite module ( http://www.iis.net/download/urlrewrite ) and the built in (in ASP.NET 4.0) Routing Engine ( http://msdn.microsoft.com/en-us/library/cc668201.aspx ).
The URL Rewrite module is external to your application and it translates incoming URLs to regular .aspx URLs. You are responsible for generating the links with .html. It is good if you are adding it to an existing application.
The built in routing can generate urls based on routes and is configured in Global.asax (usually) with code.
Right click on the project.
Add new...
pick the HTML file type.
Some people prefer to use a different extension (or even none at all) in order to hide the technology used to develop the site.
Bear in mind that you would have to properly configure IIS to let the .net engine handle the .html file types.