Freeing up space on your server

by AnthonyDang 3. February 2010 06:24

Yesterday we went to install service pack 2 on a Windows  Server 2008 machine. It turns out you need at least 5GB free on C: which we didnt have. After deleting everything we possibly could, including running CCleaner and making the Page File non-existant we were still 400MB off the mark.

 

 Then I noticed a system file c:\hiberfil.sys which was 3GB.

 

Well it turns out that Windows Server 2008 still allocates space for a hibernate file. Who would want to hibernate their Live server?

 

Anyway, this is how to gain an exta 3GB...

 

C:\Users\Administrator>powercfg.exe /hibernate off

 

That's it!

 

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Hosting

Problem: Inserting custom media types in the WYSIWYG of Umbraco 4.0.2.1 shows blank.gif instead of the correct Url

by AnthonyDang 25. January 2010 15:37
The Scenario
We had a custom media type called Image. We did this to store more information about each image that was uploaded.

The Problem
The CMS user wants to insert the image to the WYSIWYG of one of the content nodes but sees blank.gif inserted into the Url field when they click on the custom media type. This does not occur for standard Umbraco files.

Investigation
I used Charles to see what Umbraco was doing when a user clicks. Umbraco makes a call to ~/umbraco/dialogs/imageViewer.aspx to get the url. Let's take a look at the source code...


protected void Page_Load(object sender, System.EventArgs e) { //Response.Write(umbraco.helper.Request("id")); //Response.End(); // Put user code to initialize the page here if (Request.QueryString["id"] != null) { if (Request.QueryString["id"] != "") { //TODO: fix Nasty FAST'N'CANELINE HACK. .. int MediaId = int.Parse(Request.QueryString["id"]); image.Controls.Clear(); int fileWidth = 0; int fileHeight = 0; string fileName = "/blank.gif"; string altText = ""; try { cms.businesslogic.media.Media m = new cms.businesslogic.media.Media(MediaId); // TODO: Remove "Magic strings" from code. try { fileName = m.getProperty("fileName").Value.ToString(); } catch { try { fileName = m.getProperty("umbracoFile").Value.ToString(); } catch { fileName = m.getProperty("file").Value.ToString(); } } altText = m.Text; try { fileWidth = int.Parse(m.getProperty("umbracoWidth").Value.ToString()); fileHeight = int.Parse(m.getProperty("umbracoHeight").Value.ToString()); } catch { } string fileNameOrg = fileName; string ext = fileNameOrg.Substring(fileNameOrg.LastIndexOf(".")+1, fileNameOrg.Length-fileNameOrg.LastIndexOf(".")-1); string fileNameThumb = GlobalSettings.Path + "/.." + fileNameOrg.Replace("."+ext, "_thumb.jpg"); image.Controls.Add(new LiteralControl("<a href=\"" + GlobalSettings.Path + "/.." + fileNameOrg + "\" title=\"Zoom\"><img src=\"" + fileNameThumb + "\" border=\"0\"/></a>")); } catch { } image.Controls.Add(new LiteralControl("<script>\nparent.updateImageSource('" + GlobalSettings.Path + "/.." + fileName.Replace("'", "\\'") + "','"+altText+"','" + fileWidth.ToString() + "','" + fileHeight.ToString() + "')\n</script>")); } } }


Let's ignore the shamefullness of the code. We've all had our bad moments, and open source projects are bound to have some things like this. Lets comment on what the code does.

Notice this line:
string fileName = "/blank.gif";

Now notice that the bottom catch is empty. This catch is hit whenever a file does not have one of these attibutes:fileName, umbracoFile, file. So filename is never set to anything.

The solution
The last catch needs to get your custom media type. In our case:
Media m = new Media(MediaId);
fileName = m.getProperty("Image").Value.ToString();


That is the fix for Umbraco. So you have a couple options on how to implement it.

1. You can recompile Umbraco's source then redeploy.

2. If you don't want to recompile Umbraco you can can create a new file called ImageViewer.cs that inherits from umbraco.dialogs.imageViewer. Copy and paste the code, do your fix, then modify the ~/umbraco/dialogs/imageViewer.aspx file to inherit from your new file.

I.e. Change the header:
<%@ Page Language="c#" CodeBehind="imageViewer.aspx.cs" AutoEventWireup="True" 
Inherits="umbraco.dialogs.imageViewer" %>


To this:
<%@ Page Language="c#" CodeBehind="MyImageViewer.aspx.cs" AutoEventWireup="True" 
Inherits="My.Project.UmbracoExtensions.MyImageViewer" %>


The downside of both methods is that you will overwrite your changes if you upgrade Umbraco.


The awesome solution
Here is a solution that is awesomely hilarious. Using the already installed Urlrewriting.Net module that comes with Umbraco.

1. Create a new file called ImageViewer.aspx in your project somewhere. Mine was in ~/UmbracoExtensions/

Make the code behind inherit from umbraco.dialogs.imageViewer. Copy and paste the code, do your fix.

2. Open ~/config/UrlRewriting.config and add this entry:

<add name="ImageViewer"
          virtualUrl="~/umbraco/dialogs/imageViewer.aspx(.*)"
          rewriteUrlParameter="IncludeQueryStringForRewrite"
          redirectMode="Permanent"
          destinationUrl="~/UmbracoExtensions/ImageViewer.aspx$1"
          redirect="Application"
          ignoreCase="true" />


This redirects ~/umbraco/dialogs/imageViewer.aspx to your new ~/UmbracoExtensions/ImageViewer.aspx and passes the query string which allows the lookup of the file.

3. Open your ~/web.config and add /UmbracoExtensions/ to your umbracoReservedPaths under appSettings. This allows your newly created file to be redirected to.

That's it!

I find this solution absolutely hilarious! But it means I will not get undone by an upgrade. Hopefully they will eventually fix the imageViewer class to look for other files.

UPDATE
Ok after all that, I found out that you just need to change the alias name in the cmsPropertyType in the database.

First check if your file alias is being used more than once. In our case we had an Image file type, and a field in a document type called Image. So we have to modify the correct one.

Here is how to check your table:
SELECT * FROM [YOUR_DATABASE].[dbo].[cmsPropertyType]
  WHERE Alias LIKE 'Image'


To figure out which was which I did this really lazily. I had a synced db already on dev, so I just changed the alias of one to see if it would change in Umbraco. Note that you must bump the config for the alias to change in Umbraco.

Here is the sql to update your file type alias:
UPDATE [YOUR_DATABASE].[dbo].[cmsPropertyType]
  SET Alias = 'umbracoFile'
  WHERE Alias in ('YOUR_FILE_TYLE_ALIAS') // for multiple file types
  AND id !=  // line is optional



So it turns out there was no coding involved after all. Well at least I learned heaps about how Umbraco was structured :)


Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

A problem using sIFR for menus that link to databound forms in IE7

by AnthonyDang 6. August 2009 03:39

This is quite possibly the most interesting/annoying/crazy quirk/bug I have ever come across.

Scenario

Your site has a sIFR menu. One of the links goes to a typical databound form (in our case an update user details form).

Problem

The user modifies a field and submits. The database table shows the change. However, when you navigate back to the form using your sIFR menu link, you notice the old value(s) in the fields. The correct values only appear once you clear your cache. This problem only occurs in IE7.

Reason

It turns out that the sIFR link is not a normal link. It is essentially like hitting the enter key in the address bar of a page that is already loaded. The browser merely loads from its cache. No matter how many times you click that link!

Solution

In the code behind of your form on page load call this:

Response.Cache.SetCacheability(HttpCacheability.NoCache);

 

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , ,

.Net

Meta tags and Umbraco

by AnthonyDang 17. June 2009 12:01

You’d think that you could do something like this to get meta description and keywords from umbraco

 <meta name="description" content="<umbraco:Item runat='server' field='PageDescription'/>" />

   

Unfortunately umbraco will render this:

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><meta name="description" content="&lt;umbraco:Item runat='server' field='PageDescription'/>" /> 

 

The solution is inline xslt:

<umbraco:Item ID="Item" Field="PageDescription" runat="server" Xslt="concat('<meta name=&quot;description&quot; content=&quot;',{0},'&quot;/>')" XsltDisableEscaping="true"></umbraco:Item>

 

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

.Net | Umbraco

Selection Problem with Custom Media Type Content in Umbraco 4

by AnthonyDang 4. March 2009 13:41

[Entry migrated from suite101.thefarmdigital.com.au]

The Problem

You have a custom media type. You want to add a link to it in the WYSIWYG editor. 

You go to add a link as normal, except in the "Insert/Edit Link" pop up, you click on the "Media" tab. You notice that when you click on it, no url is inserted in the Url field. 

 

The problem is due to this method in the Umbraco source:

private static string findMediaLink(Media dd, string nodeLink)
{
  Guid uploadGuid = new Guid("5032a6e6-69e3-491d-bb28-cd31cd11086c");
  foreach (Property p in dd.getProperties)
  {
    if (p.PropertyType.DataTypeDefinition.DataType.Id == uploadGuid 
	&& !String.IsNullOrEmpty(p.Value.ToString()))
    {
      return p.Value.ToString();
    }
  }
  return "";
}

This method is called from the overrided Render(ref XmlTree tree) method in Umbraco's loadMedia class. Here is the code block: 

string nodeLink = findMediaLink(dd, dd.Id.ToString());
if (!String.IsNullOrEmpty(nodeLink))
{
    xNode.Action = "javascript:openMedia('" + nodeLink + "');";
}
else
{
    xNode.Action = null;
    xNode.DimNode();
}

Notice that when findMediaLink() is called, your custom media type is never going to return  "5032a6e6-69e3-491d-bb28-cd31cd11086c" as a Guid. So your media type never gets assiged it's openMedia action, and xNode.DimNode() will always be called.

 

The Work Around

You must replace the Umbraco media tree handler with your own one. We called ours "MediaTree".

Here's how:

  • Create a class (eg. MediaTree) that inherits from loadMedia (see code below)
  • Copy and paste the Render(ref XmlTree tree), and findMediaLink(Media dd, string nodeLink) methods from loadMedia.cs into your new class
  • Modify the findMediaLink(Media dd, string nodeLink) method to get the Guid from your custom media type, and check if it is equal to p.PropertyType.DataTypeDefinition.DataType.Id (see code below)

 

Here's the class:

public class MediaTree : loadMedia
{
    public MediaTree(string application) : base(application) { }

    public override void Render(ref XmlTree tree)
    {
        Media[] docs;

        if (m_id == -1)
            docs = Media.GetRootMedias();
        else
            docs = new Media(m_id).Children;

        foreach (Media dd in docs)
        {
            XmlTreeNode xNode = XmlTreeNode.Create(this);
            xNode.NodeID = dd.Id.ToString();
            xNode.Text = dd.Text;

            // Check for dialog behaviour
            if (!this.IsDialog)
            {
                if (!this.ShowContextMenu)
                    xNode.Menu = null;
                xNode.Action = "javascript:openMedia(" + dd.Id + ");";
            }
            else
            {
                if (this.ShowContextMenu)
                    xNode.Menu = new List(new IAction[] { ActionRefresh.Instance });
                else
                    xNode.Menu = null;
                if (this.DialogMode == TreeDialogModes.fulllink)
                {
                    string nodeLink = findMediaLink(dd, dd.Id.ToString());
                    if (!String.IsNullOrEmpty(nodeLink))
                    {
                        xNode.Action = "javascript:openMedia('" + nodeLink + "');";
                    }
                    else
                    {
                        xNode.Action = null;
                        xNode.DimNode();
                    }
                }
                else
                {
                    xNode.Action = "javascript:openMedia('" + dd.Id.ToString() + "');";
                }
            }
            xNode.HasChildren = dd.HasChildren;

            if (this.IsDialog)
                xNode.Source = GetTreeDialogUrl(dd.Id);
            else
                xNode.Source = GetTreeServiceUrl(dd.Id);

            if (dd.ContentType != null)
            {
                xNode.Icon = dd.ContentType.IconUrl;
                xNode.OpenIcon = dd.ContentType.IconUrl;
            }

            tree.Add(xNode);
        }
    }

    private static string findMediaLink(Media dd, string nodeLink)
    {
        TheFarm.Umbraco.Controls.MultiMediaUploadDT mmDT = 
		new TheFarm.Umbraco.Controls.MultiMediaUploadDT();
        Guid farmUpload = mmDT.Id;

        Guid uploadGuid = new Guid("5032a6e6-69e3-491d-bb28-cd31cd11086c");
        foreach (Property p in dd.getProperties)
        {
            if ((p.PropertyType.DataTypeDefinition.DataType.Id == uploadGuid || 
		p.PropertyType.DataTypeDefinition.DataType.Id == farmUpload) 
		&& !String.IsNullOrEmpty(p.Value.ToString()))
            {
                return p.Value.ToString();
            }
        }
        return "";
    }

}

Note: For this to work your custom media class must contain a Guid.

eg.

public override Guid Id 
{ 
    get { return new Guid("{12345678-ABCD-EFGH-IJKLM-NOPQRSTUVWX}"); } 
} 

Now go to the database and edit the umbracoAppTree table.

public override Guid Id 
{ 
    get { return new Guid("{12345678-ABCD-EFGH-IJKLM-NOPQRSTUVWX}"); } 
} 

That's it.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

.Net | Umbraco

// Website built by The FARM