Deploying a WCF Data Service to a server that has WebDAV installed

Here’s a simple one, that was fairly annoying:

I deployed a WCF Data Service to a site today, and while I was testing all of the operations I found that both the PUT and DELETE verbs weren’t working. At first, a 405 Method Not Allowed was being returned. I placed the service within an Umbraco site so I just figured that was where the conflict was.

After some digging around on the internet, I came across across ASP.NET MVC got 405 error on HTTP DELETE request?, from Stack Overflow, which it stated that the issue was related to WebDAV. The solution was to remove the WebDAVModule. That got rid of the 405, but unfortunately didn’t resolve the issue.

The requests started returning a 200 status code, which was good, but the page that was coming back was a 500 error. Because I wasn’t testing the service on the actual machine, I wasn’t seeing the actual error. So I logged on to the server and the tests showed the following error:

HTTP Error 500.21 – Internal Server Error
Handler “WebDAV” has a bad module “WebDAVModule” in its module list

(Gotta’ love more detailed errors.) From there I found How can I get OData DELETE to work?, also from Stack Overflow, which gave a good explanation of what was happening and how to solve it. Apparently, WebDAV blocks the DELETE and PUT requests (thanks a lot WebDAV…) and so the solution is to remove WebDAV or disable it on your site. You can completely disable WebDAV as follows:

<system.webServer>
    <modules>
        <remove name="WebDAVModule" />
    </modules>
    <handlers>
        <remove name="WebDAV" />
    </handlers>
</system.webServer>

Thank you to Stack Overflow and all those that contribute to it!

Advertisements

Using CSS Classes for Image Alignment in TinyMCE

I had a problem with aligning images in the TinyMCE editor in Umbraco 4.7.1.1. There are two ways a user can align images: a) Using the paragraph alignment button, and b) Using styles defined for the editor. We wouldn’t need option b) at all except that, when you have margins automatically applied to the images, things can get messy. Even then, annoyingly enough, option b) doesn’t always work, depending on what tag the image is nested in. So I searched for a better solution. I wanted the user to be able to still use the alignment tool, but I wanted the tool to apply class instead of using the style attribute to the float the image.

Eventually, I found a blog post, Patching TinyMCE For Better Left/Right Aligned Images, by Gareth Senior, that included a simple solution to my problem. Gareth included code for a simple patch that made all my TinyMCE dreams come true. I’ll include the same code here, only I’ll also document how I implemented the changes in Umbraco.

The simple change is made to the tiny_mce_src.js. Normally, you make the changes to tiny_mce_src.js, then minify the file and use the minified version. The Umbraco installation includes a minified version of the file, but apparently it’s not used. I made the following changes to umbraco_client/tinymce3/tiny_mce_src.js, and it fixed things for me really nicely:

3469    case 'float':
3470+      tinymce.DOM.removeClass(n, 'align-left');
3471+      tinymce.DOM.removeClass(n, 'align-right');
3472+      if (v != "") tinymce.DOM.addClass(n, "align-" + v);
3473       isIE ? s.styleFloat = v : s.cssFloat = v;
3474       break;

This will add the class “align-left” or “align-right” to the image when the alignment options are used from the tool bar. You can then use those to create styles that will compensate for the margins.

NOTE: Be sure to clear the browser cache, or the browser will hold on to the old version and it will seem like it did nothing. Oh and remember that you’ll have to make this change again when you upgrade Umbraco as the upgrade will replace the edits.

Edit: 5/16/2012 – This also works in Umbraco 4.7.2.

Using The TinyMCE Color Picker in Umbraco

The Umbraco folks, for whatever reason, decided to strip out the text color picker in TinyMCE. I found that many of my users still need it, and I would rather not create custom styles for each of them. After a lot of blundering around, I found this Our Umbraco forum post which outlines how to add the color picker back in. I took it a little further and found it was real easy to limit the palette of colors available to the user. This can all be done in the tinyMceConfig.config. I’ve only used this on Umbraco 4.7.1.1.

Steps are as follows:

1.) Open config/tinyMceConfig.config in a text editor.

2.) To add the color picker button back to toolbar, add the following command to the <commands> node:

<command>
    <umbracoAlias>mceForeColor</umbracoAlias>
    <icon>images/editor/forecolor.gif</icon>
    <tinyMceCommand value="" userInterface="true" frontendCommand="forecolor">forecolor</tinyMceCommand>
    <priority>21</priority>
</command>

NOTE: Customize the priority based on where you’d like the button to be placed. I gave mine a “21” and I adjusted the others accordingly.

3.) To remove the “More Colors” link from the color picker, add the following to the <customConfig> section:

<config key="theme_umbraco_more_colors">false</config>

4.) Then to limit the palette available to the user, also add this key to the <customConfig> node:

<config key="theme_umbraco_text_colors">000000,0079E3,FF0033</config>

NOTE: Include your own RGB colors here. In my case, I’ve only decided to make these three (000000,0079E3,FF0033) available.

5.) “Touch” the web.config to recycle the application so the changes will take effect.

6.) Log in to the Umbraco backend and in the TinyMCE/Rich Text Editor/wysiwyg data type, enable the color picker button.

Presto! That’s it, the editor should now show the color picker.