mBerube.net
A journey to .Net

From IIS 6 to IIS 7.5 : not as easy as it looks

Sunday, 27 June 2010 15:23 by mBerube
(Also available in: français)

I wanted to do some changes to my blog engine yesterday. I took my production code which run perfectly at my hoster on IIS 6 and I put it on my dev server on IIS 7.5. Nothing worked ! Error 401 (authentication) on every pages, even with Accept Anonymous request enabled. After many tries and searches, here's what I did to make it work, hopping it could be usefull for some of you :

  • 1st, I've created the application and put it in the Classic .Net AppPool
  • I verified that the default document was default.aspx. It wasn't so I put it on the top of the list.
  • Then, I checked if the user of the appPool had the required rights on the files. It's a little bit harder to check with IIS 7 because every appPool has a custom user. The only thing to check is that the IIS_IUSRS group has the required rights on the folder and it was ok.
  • It still doesn't work. I then saw on a blog post that even if you gave Anonymous user access to the site, you still need to setup which user to use as ananymous. My error was there and as soon as I put the anonymous user credential to "Application Pool Identity", boom, everything worked perfectly.

There's one last problem with an easy workaround but I still not understand. When i use the url http://myservername/blog (with a lower case b), it doesn't work BUT with the url http://myserbername/Blog (with an upper case B), it works? The application name is "Blog" but I didn't think that IIS treat URL as case sensitive. I will continue to look for that and I will keep you in touch.

Thanks, happy developping.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories:   BlogEngine.NET
Actions:   E-mail | del.icio.us | Permalink | Comments (0) | Comment RSSRss comment feed

When you spend to much time moderating, introduce a captcha

Friday, 9 April 2010 20:56 by mBerube
(Also available in: français)

After 3 months moderating comments manually, I had to introduce a captcha due to an exponential increase of the spam in the last month. After spending many hours trying to integrate recaptcha, I finally found a post on Code Capers which was exactly what I needed. Thank Michael.

It's simple, a little less secure than recaptcha but should be good enough.

Sorry for the legetimate users but you know like me it's a necessary evil.

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories:   BlogEngine.NET
Actions:   E-mail | del.icio.us | Permalink | Comments (0) | Comment RSSRss comment feed

Little bug, big night

Thursday, 1 April 2010 22:44 by mBerube
(Also available in: français)

Last week, I was trying to find a bug on this blog (with the Next/previous page link). Because I've done a lot of changes in BlogEngine.Net to allow multiple languages, I started by looking into my code. The situation was that the link was formatted like this : http://blog.mberube.net/en/?page=2 (without the page name). There's the results of my tests :

  1. On webdev server (Cassini), it worked.
  2. On my local le IIS 7 on Win7, it worked.
  3. On my QA web server (IIS 6 on WS2003), it didn't work.
  4. On my hoster (Proweb) server on II6 on WS2003, it didn't work either.

 

So good sign : I can reproduce the bug on my QA server. But to find it, I had to fight a lot with the Remote Debugger and I'll talk about this in another post, giving the instructions how to setup and use remote debugger on a network without domain users. 

I finally found that because the path had no file name, IIS was rejecting the request before the URL rewriter in my application could resolve it. On my QA server, I added the ASP.Net engine in wildcard application maps for all files not found and it works at first try. Yé !

 

I did exactly the same thing on my hosted server, it doesn't work. Hmmmm... 

I did a quick fix for the bug but I would like to understand that mystery. If you have suggestions or ever solved that kind of issue, please leave a message.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories:   BlogEngine.NET
Actions:   E-mail | del.icio.us | Permalink | Comments (0) | Comment RSSRss comment feed

Integrate SyntaxHighlighter to BlogEngine.Net

Monday, 5 October 2009 23:22 by mBerube
(Also available in: français)

I was writing my first technical post (about asp.net MVC) and I realized that I had no way to display code snippets properly. It's inadmissible for a programming blog to not have that kind of feature. I started looking for a tool and I quickly found SyntaxHighlighter, an open-source product written in javascript and widely used on the Net. Documentation is clear and installation seems simple. It has been a little more complex that advertised but I've been able to integrate it in BE.Net with a little work.

Download SyntaxHighlighter

By going to the "official" site, we can download version 1.5. But, on the author personal site, we can download the new 2.0 version. I choose this one. The package contains some css and javascripts required for that tool to work properly. To get the formatting, you just have to wrap your code in a <PRE> tag with a class corresponding to the language to display. Ex :

<pre class="brush: html;">
<b>bold text</b>
</pre>

The scripts work very well, it's when you try to include it in BE.NET that the fun begins ! BE.Net use many URL rewriting rules, so it's difficult to refer the script relatively to the current page so we must do the reference to the application root.  The first replex is to put runat="server" on the scripts and to use tilde (˜) to translate to the application root. Unfortunately, it doesn't work because with that tag, the javascript code is evaluated by the compiler and some of the code in SH have errors (or at least, synx that VS2008 doesn't like. I also tried to integrate so code into the markup (ex: <%= SiteRoot() %>/Scripts/shcore.js) but it doesn't work either because BE.Net tried to add Meta tags at runtime, throwing this exception.

I finally rely on the ScriptManager, that help for 2 things : I can refer my scripts using the tilde (˜) now that it's a server control and I can at the same time combine my scripts for better performance.

<asp:ScriptManager ID="ScriptManager1" runat="server">
    <CompositeScript>
        <Scripts>
            <asp:ScriptReference Path="~/Scripts/shCore.js"/>
            <asp:ScriptReference Path="~/Scripts/shBrushBash.js"/>
            <asp:ScriptReference Path="~/Scripts/shBrushCpp.js"/>
            <asp:ScriptReference Path="~/Scripts/shBrushCSharp.js"/>
            <asp:ScriptReference Path="~/Scripts/shBrushCss.js"/>
            <asp:ScriptReference Path="~/Scripts/shBrushDelphi.js"/>
            <asp:ScriptReference Path="~/Scripts/shBrushDiff.js"/>
            <asp:ScriptReference Path="~/Scripts/shBrushJava.js"/>
            <asp:ScriptReference Path="~/Scripts/shBrushJScript.js"/>
            <asp:ScriptReference Path="~/Scripts/shBrushPlain.js"/>
            <asp:ScriptReference Path="~/Scripts/shBrushPython.js"/>
            <asp:ScriptReference Path="~/Scripts/shBrushRuby.js"/>
            <asp:ScriptReference Path="~/Scripts/shBrushPerl.js"/>
            <asp:ScriptReference Path="~/Scripts/shBrushSql.js"/>
            <asp:ScriptReference Path="~/Scripts/shBrushVb.js"/>
            <asp:ScriptReference Path="~/Scripts/shBrushXml.js"/>
            <asp:ScriptReference Path="~/Scripts/shBrushJavaFX.js"/>
            <asp:ScriptReference Path="~/Scripts/shBrushPowerShell.js"/>
        </Scripts>
    </CompositeScript>
</asp:ScriptManager>

The drawback of using the ScriptManager is that my implementation of BE.Net isn't totally comptible with .Net 2.0 anymore but how cares, .Net 4 is about to be release so we must live in the present so welcome .Net 3.5 !

Integration into the blog editor

BE.Net 1.5 useTinyMCE 3 to edit blog posts. The editor has a WYSIWYG mode but also an HTML mode. It's possible to generate the required markup to integrate code into posts but somes opertions still highly manual and error prone like convert special characters, configuring options, etc. So I ask Google and I found someone has already solve that problem and developped a plugin SyntaxHighlighter for Tiny MCE. It wasn't working at first but just a little tweeking and we're done ! Also, the character encoding wasn't done properly but a little search in StackOverflow and everything is all right.

function Save_Button_onclick() {
    var lang = document.getElementById("ProgrammingLanguages").value;
    var code = WrapCode(lang);
    code = code + HtmlEncode(document.getElementById("CodeArea").value);
    code = code + "</pre> "
    if (document.getElementById("CodeArea").value == '') {
        tinyMCEPopup.close();
        return false;
    }
    tinyMCEPopup.execCommand('mceInsertContent', false, code);
    tinyMCEPopup.close();
}

function HtmlEncode(s) {
    var el = document.createElement("div");
    el.innerText = el.textContent = s;
    s = el.innerHTML;
    delete el;
    return s;
}

Good ! Eveything works and now that I finishing reading Professional ASP.NET MVC 1.0, I've many ideas to explore and share with you.

See you next time

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories:   BlogEngine.NET
Actions:   E-mail | del.icio.us | Permalink | Comments (0) | Comment RSSRss comment feed

The fun of merging

Tuesday, 8 September 2009 21:37 by mBerube
(Also available in: français)

To create that multilingual blog, I used the EnhacedBlogEngine.Net code base to identify all the hacks required to enable multiple languages and then, I had to port all these changes to the latest source code of BlogEngine.Net. What a task ! 60% of the job was pretty easy, just using winmerge and merge the changed lines to the BE.net source file. But, in the newest part of the code, some of the logics doesn't work so well (for example, the nested comment feature) and some bug had to be fixed in the URL rewrite logic. Also, most of the widgets wasn't fully localized. Finally, the theme I choose came from a earlier version of BlogEngine.Net so I had to tweek many things (ex : the widget zone) to make it behave as expected.

I still in the debug process and thanks to the wonderfull Elmah error logging and reporting, I can keep an eye on every errors that occured on that site.

If you already face that kind of challenge, I've a question for you : how can I organize my code (in my source control) to make it easier to merge my changes into a future version of BlogEngine.Net ?

Thanks and feel free to comment.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories:   BlogEngine.NET
Actions:   E-mail | del.icio.us | Permalink | Comments (0) | Comment RSSRss comment feed