Can I make IIS add (inject) HTML to every page it serves? - iis

I would like to add some HTML to every page that our IIS 6 server serves. It's serving static HTML for the most part. Is this something IIS or an extension can do? I would need some control over how and where the HTML is injected, in this case before the tag. Thanks for your suggestions!

Natively I believe the only thing you can do is insert a document footer (on the Documents tab).

If you're familiar with ASP.NET, you could write a HTTP Response Filter to do that.
Read this article by Milan Negovan.
The HttpResponse class has a very useful property:
public Stream Filter {get; set;}
MSDN provides a helpful description of
this property: "Gets or sets a
wrapping filter object used to modify
the HTTP entity body before
transmission." Confused? In other
words, you can assign your own custom
filter to each page response.
HttpResponse will send all content
through your filter. This filter will
be invoked right before the response
goes back to the user and you will
have a change to transform it if need
be.
This could be extremely helpful if you
need to transform output from "legacy"
code or substitute placeholders
(header, footer, navigation, you name
it) with proper code. Besides, at
times it's simply impossible to ensure
that every server control plays by the
rules and produces what you expect it
to. Enter response filters.
The Filter property is of type
System.IO.Stream. To create your own
filter you need to derive a class from
System.IO.Stream (which is an abstract
class) and add implementation to its
numerous methods.

I was able to inject some CSS before the using the URL Rewrite Module, via an outbound rule:
<rewrite>
<rules>
<outboundRules rewriteBeforeCache="true">
<rule name="Add custom CSS" preCondition="IsHTML">
<match filterByTags="None" pattern="</head>" />
<action type="Rewrite" value="<link rel="stylesheet" href="/path/to/custom/styles_override.css"></head>" />
</rule>
<preConditions>
<preCondition name="IsHTML">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
</preConditions>
</outboundRules>
</rules>
</rewrite>
You should be able to do the same with html content, instead of css...

In IIS proper, you can add a footer, which is great for a copyright line, or similar. If you want more control, to truly "inject", I would create an HTTP Handler (.NET) that handles .html requests and adds what you need.
If you are "old school", use ISAPI filters instead. Too much work for my tastes.

Related

Add Thumbnail / picture on the blog list summary orchard

How do I add image / thumbnail before the blog summary using orchard cms?
Please give step by step instruction because I'm still new using this cms
i already tried this technique but still not working
Thank you
I would suggest that you enable the shape tracer module in Orchard, this will assist you in understanding exactly what is being pulled through on the customer view side of things.
Read more about it here:
http://docs.orchardproject.net/en/latest/Documentation/Customizing-Orchard-using-Designer-Helper-Tools/
Firstly when you are editing your Placement.info file, it does not always pull through immediately, I find that you have to recycle the application pool in IIS for the specific site.
Also get a better understanding of placement info here: http://docs.orchardproject.net/Documentation/Understanding-placement-info
Secondly you need to understand the order in which elements are being loaded before you change any placement of it.
I followed the following steps:
Created a blog called 'blog'
Edited the Content Type called 'Blog' and added the a field called 'image' as a 'Media Library Picker Field'
I viewed the '/blog' in the customer side and inspected it with 'shape tracer'
I found that the detail view was loading for the blog description/summary;
The 'Parts_Blogs_Blog_Description' which is the summary was loading in 'content:before' by default;
The 'Fields_MediaLibraryPicker' was loading at 'content:after'
So, in this case you will have to change both:
If you had to place both in 'content:before', then Orchard would still not know which one to put first. This is what you need to put in your placement.info file:
<Match ContentType="Blog">
<Match DisplayType="Detail">
<Place Fields_MediaLibraryPicker-image="Content:1"
Parts_Blogs_Blog_Description="Content:2" />
</Match>
</Match>
If you want to do this for Blog Posts, you will do it exactly the same. But just refer to the blog post content type. The 'Media Library Picker Field' was called 'Images'. And you have to change the 'Part_Common_Body' placement.
<Match ContentType="BlogPost">
<Place Fields_MediaLibraryPicker-Images="Content:1"
Parts_Common_Body="Content:2" />
</Match>
To remove the Title and metadata from the images selected:
<Match ContentType="Image">
<Match DisplayType="Summary">
<Place Parts_Title_Summary="-"
Parts_Common_Metadata_Summary="-"/>
</Match>
</Match>
Also make sure that you selected images for the blog and blog posts. The Placement.info file can be found in your theme folder.
This was done in Orchard 1.10.2. I do not know if this will differ in other versions.
You should use the build in MediaLibraryPickerField as described in the second answer, but in your case for the Blog instead of the BlogPost:
Attach a Media Library Picker Field to your 'Blog' content type
Edit your theme's placement.info and include something like this:
<Match ContentType="Blog">
<Match DisplayType="Summary">
<Place Part_Image_Summary="Content:before" />
</Match>
</Match>

Using URL Rewrite to change part of URL

I'm trying to use an URL Rewrite on an IIS 8.0 to rewrite existing URL:s on a developer machine. The reason for this is that I don't want to change existing (old) code.
What I'm trying to achieve is to change the following code in the response stream:
Foo Page
into:
Foo Page
But when I'm trying, I end up with:
Foo Page
And as you all know, this is not a very satisfying result.
So - how do I do this rewrite proper to achieve what I'm trying to do?
I know there are better ways of doing this, using application variables etc., but it's an old solution and I don't want to mess too much with the application itself. I want to keep the changes to a minimum. At least to begin with.
The rules I tried look like this:
<system.webServer>
<rewrite>
<outboundRules>
<rule name="foo.com" enabled="true">
<match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script" pattern="foo.com" />
<action type="Rewrite" value="foo.localhost" />
</rule>
</outboundRules>
</rewrite>
</system.webServer>
I guess there is some regex magic I should be using.
Your rule needs to be changed to:
<rule name="foo.com" enabled="true">
<match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script" pattern="^(.*)foo.com(.*)$" />
<action type="Rewrite" value="{R:1}foo.localhost{R:2}" />
</rule>
In the pattern, ^(.*) will match anything (0 or more characters) from the beginning before foo.com and (.*)$ anything after foo.com until the end.
You can then use the back references in the action, where {R:1} will take the value matching (.*) before foo.com and {R:2} the value matching (.*) after foo.com

Joomla 2.5 ACL restrict to specific features/views

I seem to be having a problem identifying how to restrict Joomla 2.5 back-end users to specific features / Views in a custom component I am writing. According to my understanding I should be able to add my views as a section in the access.xml file. I have attempted this by naming a section the same name as my view but I don't seem to be able to change the access to that view independently from the component as a whole. Does anybody have a more in depth example I can review or tips? Is this even possible?
I believe what you are trying to do is not supported by Joomla.
My suggestion is to add a custom rule for views in access.xml
<section name="component">
<action name="core.admin" title="JACTION_ADMIN" description="JACTION_ADMIN_COMPONENT_DESC" />
<action name="core.manage" title="JACTION_MANAGE" description="JACTION_MANAGE_COMPONENT_DESC" />
<action name="core.create" title="JACTION_CREATE" description="JACTION_CREATE_COMPONENT_DESC" />
<action name="core.delete" title="JACTION_DELETE" description="JACTION_DELETE_COMPONENT_DESC" />
<action name="core.edit" title="JACTION_EDIT" description="JACTION_EDIT_COMPONENT_DESC" />
<action name="core.edit.state" title="JACTION_EDITSTATE" description="COM_CATEGORIES_ACCESS_EDITSTATE_DESC" />
</section>
<section name="views">
<action name="core.admin" title="JACTION_ADMIN" description="JACTION_ADMIN_COMPONENT_DESC" />
</section>
Then save your view in the #__assets table with a name like com_component.view.playerlist,
in the rules field you should save a JSON encoded list of your rules:
{"core.admin":{}}
You can check if current user can or cannot access a determinate section using JAccess
$user_id=JFactory::getUser()->id;
$has_permission = JAccess::check($user_id,'core.admin','com_component.view.playerlist');
if($has_permission){
draw_view();
}else{
JError::riseError(403,JText::_('PERMISSION_DENIED'));
// or
JError::raiseWarning(403,JText::_('PERMISSION_DENIED'));
}
If you have any doubt, feel free to comment.

Adding expire headers to Web.Config file

I'm looking to add expire headers to my website so I can set a cache time for the files.
I've found the following the example, but I'd like to set it to only cache JPG, PNG, GIF, JS and CSS files if possible?
<system.webServer>
<staticContent>
<clientCache cacheControlMaxAge="14.00:00:00" cacheControlMode="UseMaxAge"/>
</staticContent>
</system.webServer>
Thanks for any help!
What you can do is to create web.config files in the folders where your files are. (You might have folder such "Images" for images and "Js" for javascript files, "Css" for style sheets... etc.) Then, you paste yor code in those files. By doing that you apply your cache settigs to all files in those folders, regardless of the file type. This is more flexible method than applying cache settings to a particular file extension.
IIS does NOT support dynamic expires headers for static content.
You can add a static expires header this way:
<system.webServer>
<staticContent>
<clientCache httpExpires="Sun, 29 Mar 2020 00:00:00 GMT" cacheControlMode="UseExpires" />
</staticContent>
</system.webServer>
Source:
The Official Microsoft IIS site
There is a similar question here:
IIS 7.5 How do you add a Dynamic HTTP Expires Header
As already pointed out using another web.config in the specific folder is probably the best option.
However you can override the cache control header with and outbound rewrite rule:
<system.webServer>
...
<rewrite>
<outboundRules>
<rule name="RewriteCacheControlForHTMLFiles" preCondition="jsFile">
<match serverVariable="RESPONSE_Cache_Control" pattern=".*" />
<action type="Rewrite" value="max-age=86400" />
</rule>
<preConditions>
<preCondition name="jsFile">
<add input="{REQUEST_FILENAME}" pattern="\.js$" />
</preCondition>
</preConditions>
</outboundRules>
...
If you want to cache specific Items I would go the route of doing this programatically. You could use the following code to get you going. It's from microsoft, i just brought it over so you don't have to go find it. http://msdn.microsoft.com/en-us/library/ff477235.aspx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Runtime.Caching;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
protected void Button1_Click1(object sender, EventArgs e)
{
ObjectCache cache = MemoryCache.Default;
string fileContents = cache["filecontents"] as string;
if (fileContents == null)
{
CacheItemPolicy policy = new CacheItemPolicy();
policy.AbsoluteExpiration =
DateTimeOffset.Now.AddSeconds(10.0);
List<string> filePaths = new List<string>();
string cachedFilePath = Server.MapPath("~") +
"\\cacheText.txt";
filePaths.Add(cachedFilePath);
policy.ChangeMonitors.Add(new
HostFileChangeMonitor(filePaths));
// Fetch the file contents.
fileContents = File.ReadAllText(cachedFilePath) + "\n"
+ DateTime.Now.ToString();
cache.Set("filecontents", fileContents, policy);
}
Label1.Text = fileContents;
}
}

iis 7.5 url rewrite -not processing percent '%' symbol

I imported rules from IIRF into IIS URL Rewrite, and most seemed to work fine. I just noticed tho that some urls have percent symbols in them (trying to redirect some bad inbound links, with percent encoded characters in them). The regex seems to not work when the percent is in there, so I assume it is trying to interpret is as a command or something. Can't find any documentation on this, anyone know?
The accepted answer didn't work in my case, but I discovered a different way to setup the rewrite rule. This will do a 301 redirect.
Requested URL: http://www.shuttercontractor.com/m/vinyl-%E2%80%8Bshutters.aspx
Target URL: http://www.shuttercontractor.com/m/vinyl-shutters.aspx
<rule name="301 Redirect to vinyl shutters category" stopProcessing="true">
<match url="." ignoreCase="false" />
<action type="Redirect" redirectType="Permanent" url="m/vinyl-shutters.aspx" />
<conditions>
<add input="{UNENCODED_URL}" pattern="m/vinyl-%[Ee]2%80%8[Bb]shutters\.aspx" ignoreCase="false" />
</conditions>
</rule>
Basically, the match will work on any URL, and we use a condition with the UNENCODED_URL server variable to ensure the pattern matches before redirecting.
appears that the rewrite rules already undo the url encoding, so it no longer sees a %3E as that, but instead as a '<'.. so using a > in place of %3E does the trick. Now, to go fix a bunch of urls. argh.
Edit:
Also, if you hand edit the web.config (versus using the UI editor), you will need to use & lt ; for the < symbols. It's probably best to use the UI to avoid confusion.

Resources