Code injection for head and body tags

This is an open forum for any mojoPortal topics that don't fall into the other categories.

This thread is closed to new posts. You must sign in to post in the forums.
9/1/2012 3:51:11 PM
Gravatar
Total Posts 18439

Re: Code injection for head and body tags

You should not add code directly in layout.master.

What you can do is implement a custom server control that renders the doctype according to your logic and then embed the control in the layout.master in place of the raw doctype.

However, I really cannot see any benefit to changing the doctype based on the browser type. The doctype should reflect the markup in the page. You must have some unusual requirement to be doing something like that.

9/1/2012 11:52:06 PM
Gravatar
Total Posts 11

Re: Code injection for head and body tags

It's not the DOCTYPE that I need to change, but that's the position of where I need to add code. I need to add a tag just before the DOCTYPE that says something like <!-- start here -->. It can't be added using JS because it tells the server if the page is to be encrypted before sending it to the browser, and from where to start encrypting.

What we have is a server side filter that encrypts pages before delivery to a custom web browser.

Pages can be hard coded (this would lock down the whole site) or page encryption can be optional (leaving doorway pages accessible to popular browsers as the browser includes plugins that enable it to be launched from ordinary web pages). So the inclusion of the tag needs to be switchable according to condition and trigger, ie: if the first 3 letters of the page name = "enc" then that page must be encrypted.

Are there any "custom server controls for embedding into layout.master" in the portal that I can use as an example?

9/3/2012 2:37:39 AM
Gravatar
Total Posts 11

Re: Code injection for head and body tags

Wow! I have been reading up on what is involved in creating a custom control... that seems like a very long way around adding what should only take 4 lines of code, ie:

if condition {
write this }
else {
write that }

The Hello World example uses 112 lines of code and 9 included components just to write "Hello World"?

There must be a better way than that to simply modify the DOCTYPE in layout.Master.

9/3/2012 10:31:43 AM
Gravatar
Total Posts 18439

Re: Code injection for head and body tags

From your questions and statements you obviously know very little about ASP.NET development and it seems strange that you are trying to do some weird security with encrypting page content and using a custom web browser. Seems very drastic, why not just use ssl to secure a page like anyone else would? 

You seem to expect syntax like a scripting language such as classic asp or php, asp.net is not a scripting language.

<%= is just shorthand for Response.Write. That is why it can render a string. ASP.NET is not a scripting language like Classic ASP, Reponse.Write is not typically the right way to do things in ASP.NET like it was in  Classic ASP. ASP.NET WebForms is about building a control tree that does the rendering and requires understanding the lifecycle of page and control events.

The hello world article is about how to implement a custom content feature that plugs in to the cms as a UserControl, it isn't the same thing as a server control. I could write a control to do what you want in 2 minutes:

using System.Web.UI.WebControls;

namespace MyNamespace.Controls
{
public class MyDocType : WebControl
{
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
//base.Render(writer);
if (Page.Request.Browser.Type.Contains("Firefox"))
{
writer.Write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");
}
else
{
writer.Write("<!DOCTYPE html>");
}
}
}
}

1. Compile your class into a custom class library project to keep it separate from mojoPortal and avoid forking the code and put the resulting dll in the /bin folder
2. Add this near the top of layout.master
<%@ Register Namespace="MyNamespace.Controls" Assembly="MyNamespace.Controls" TagPrefix="my" %>
assmebly must match the name of the dll without the .dll extension
3. then add your control in layout.master
<my:MyDocType id="dt1" runat="server />

9/3/2012 10:36:24 AM
Gravatar
Total Posts 18439

Re: Code injection for head and body tags

all of the <portal: controls in layout.master are server controls, the only difference is that the tag/namespace registration is done in Web.config <pages><controls> section. They could have been registered at the top of layout.master but registering them in web.config is cleaner for built in controls.

9/3/2012 7:37:33 PM
Gravatar
Total Posts 11

Re: Code injection for head and body tags

Why not use SSL like everyone else? Because the ASPS Web Reader is about 100 times more secure. Unlike browsers designed to win a popularity contest, the ASPS browser is specially designed to protect web media. All media including PDF, Flash and video is most secure from all copying including screen capture and recording, and nothing can be gained from view source or cache.

http://www.artistscope.com/artis-secure-web-reader.asp

My task is to prepare some demo sites as proof of concept because it's not enough stating that any web site can be delivered via ASPS. The ASPS filter is available for both Windows and Linux servers (all distributions). I have already set up sites for Drupal, Joomla, Moodle and Wordpress on Linux, Classic ASP on Windows Server 2003, and yet to complete demos on Windows Server 2008 using .Net.

These sites will be showcased as a gallery of possible scenarios and the exercise will provide a background for support. Treatment for each is much the same, ie: adding tags and JavaScript, but none have been easier than a day just to fathom the developer's structure. Until a couple of weeks ago PHP was alien. Now I have to deal with .Net.

9/4/2012 6:35:10 AM
Gravatar
Total Posts 18439

Re: Code injection for head and body tags

Ok your explanation of what you are trying to do and why makes sense, and a solution to protect media is an interesting and difficult problem to solve. I think requiring users to install a browser plugin or custom web browser is a tough sell in many cases since users are used to being able to play videos and other media freely, but I can see it would be useful in some scenarios where you really must protect the content. Let us know how your implementation for asp.net turns out.

Best,

Joe

You must sign in to post in the forums. This thread is closed to new posts.