AJAX not working correctly in BlogEngine.NET 1.6

7. January 2012

Problem

 

I had a lot of issues getting AJAX to work correctly in BlogEngine.NET 1.6.  After updating 3 times, the request URL gets screwed up and a PageRequestManagerServerErrorException was raised with a 404 status code.

Solution

 

I am listing steps I took to get AJAX installed.  Solution to the AJAX issue is at the end of the post.

 

Steps to Installing AJAX

First I only wanted AJAX added for ASP.NET Web User Control (ASCX) files I develop.  So I didn’t add it to the entire website.

Created a simple ASCX to generate random passwords with the link of: http://www.itbrigadeinc.com/post/2012/01/07/Random-Password-Generator.aspx.

Tested this ASCX on my local development server (not in BlogEngine yet). 

Discovered I had to use the AJAX Control Toolkit instead of the AJAX Extensions that included in Visual Studio.  Can download the AJAX Control Toolkit here.

Used the .NET 3.5 version of the Toolkit since that is what I am building BlogEngine with.

Retested on local server and worked fine.

Added ASCX to BlogEngine.NET – this is where I started getting problems

Received the following error on 3rd click of the button:

Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 404.

The HTTP request was:

http://localhost:52457/BlogEngine.NET/post/2012/01/07/post.aspx?id=0fb34787-b32d-4c96-a653-aea78ca90ea4

when it should have been:

http://localhost:52457/BlogEngine.NET/post.aspx?id=0fb34787-b32d-4c96-a653-aea78ca90ea4

So it was not requesting the correct page and thereby giving the 404 error.

 

Solution

 

After much research on the internet, I found that someone had a simple solution.

Just add this script block to the end of your ASCX control and it corrects the HTTP request back to:

http://www.itbrigadeinc.com/post/2012/01/07/Random-Password-Generator.aspx

 

Solution
  1. <script type="text/javascript">
  2.     Sys.Application.add_load(function () {
  3.         var form = Sys.WebForms.PageRequestManager.getInstance()._form;
  4.         form._initialAction = form.action = window.location.href;
  5.     });
  6.  </script>

 

 

John Dorsey
IT Brigade Inc.
www.itbrigadeinc.com

ASP.NET, BlogEngine.NET ,

How to add another page to your BlogEngine.NET 1.6 Website

5. November 2011

Summary

This article describes how to add another page to your BlogEngine.NET 1.6 web blog.  The page will also be added to the main menu on your blog and can be edited with Windows Live Writer. (I use Windows Live Writer to create/edit my blogs).  See my article on Windows Live Writer.

Description

Pages are very confusing in BlogEngine.NET 1.6.  They don’t seem to be linked to anything and are not shown on the menu. 

I wanted to add an “About” page similar to the “Contact” page for my BlogEngine.NET 1.6 website.  I tried to add a page using the website Administrator functions, but that added a page that was not linked into the posts or main page.  It was lost somewhere in the blog…

Solution

Finally figured out the EASY way to do it:

1. Use the BlogEngine.NET administrator function in your website to add a new page, in my case the “About” page.  Don’t set a parent for that page.  Set the Slug to the page name – in this case: “About”.

2. Go to the site.master page in the theme you have selected and find the menu items.  Add a new menu item with the following format:

<li <%=MenuClass("About.aspx")%>><a href="<%=Utils.AbsoluteWebRoot %>page/About.aspx">About</a></li>

Note: the addition of the “page/” to link up the menu with the page created in step 1.

3. Build and deploy your website.

4. Open Windows Live Writer and “Open Recent Post”.  Select your blog and select “Pages” (not “Posts”).  Select the “About” page you created.

5. Edit your “About” page and Publish.

 

That's All!

 

John Dorsey
IT Brigade Inc.
www.itbrigadeinc.com

BlogEngine.NET, ASP.NET ,

Robots.txt – BlogEngine.NET

5. November 2011

Problem: The default robots.txt is NOT setup properly with respect to the sitemap in BlogEngine.NET.

Here’s an excellent article about robots.txt and sitemaps in BlogEngine.NET.  Sitemaps are available in BlogEngine.NET.

Here’s the default robots.txt file:

User-agent: *
Disallow: /login.aspx
Disallow: /search.aspx
Disallow: /error404.aspx
Disallow: /archive.aspx

#Remove the '#' character below and replace example.com with your own website address.
http://example.com/sitemap.axd

Note: Your robots.txt file is a file for excluding/including pages of your website from/for web robots crawling through your website.

Can view my robots.txt file by entering www.itbrigadeinc.com\robots.txt (they are public files).

 

A sitemap file provides a list of pages on your website. It’s there to help the robots find all the pages in your website.

Here’s my current sitemap: http://itbrigadeinc.com/sitemap.axd

 

Solution:  Correct your robots.txt file with your website name and remove the ‘#’ comment character.  Here’s my robots.txt after correcting it:

User-agent: *
Disallow: /login.aspx
Disallow: /search.aspx
Disallow: /error404.aspx
Disallow: /archive.aspx
http://itbrigadeinc.com/sitemap.axd

 

  John Dorsey

  IT Brigade Inc.

  www.itbrigadeinc.com

BlogEngine.NET

Dislikes with BlogEngine.NET

5. August 2011

Just a quick venting without going into details…

 

  • Adding another page – have to rebuild whole project.
  • More difficult then I like to update to new version (would like to go from 1.6 to 2.5).
  • Easier to add Flash swf than a C# user control.
  • Too much comment spam even with built-in spam protections (ended up shutting off comments).

 

But after that venting, still have to give a thumbs up to BlogEngine.NET!

 

Update, 11/4/2011:

Staying with BlogEngine.NET 1.6, too much effort/risk to go to 2.5 version.

Changed website publish options: website runs a lot faster now (see Publishing a Visual Studio Website)

BlogEngine.NET

Livening up your BlogEngine.NET Blog Entries with Windows Live Writer 2011

5. April 2011

Problem: I wanted a way to liven up my blog entries on BlogEngine.NET.  My blogs were all looking plain. The Tiny MCE Editor that comes with the BlogEngine 1.6 install is pretty basic.

Solution:  I did some little looking around on the internet and ended up seeing Windows Live Writer 2011.   I highly recommend this tool!

Note: This is another Microsoft product which I was unaware of and then it turns out the program was already installed on my Windows 7 machine...

Window Live Writer Capabilities

The program automatically connects with your blog when you start it up and allows you to add new entries (posts, pages) or modify existing ones.

It uses the themes you have setup on your blog.

Once you add a new entry or change an existing one, you can automatically publish it to your blog by simply pressing a button!

Says it works with more than BlogEngine.NET also (Wordpress, etc.) although I haven’t tried any others out.

Simple to use.

Allows Window Live Writer Plugs-ins – these are excellent and deserve additional discussion.

 

Window Live Writer Plug-Ins

Plug-ins for Window Live Writer are an excellent feature.   The official Microsoft site for  Windows Live Writer Plug-ins Page is here.  I tried a couple from the official page as listed below.  Some of these are excellent for pasting in code examples, etc.

Unfortunately, the official plug-in page is not being updated.  Not sure whether Microsoft is not supporting it well or developers are not submitting plug-ins.  Anyway there are plug-ins available directly from developers for FREE on the internet.

 

As an example here is the Polaroid Picture Plug-in…

 

Plugins I have loaded into Windows Live Writer from the official Microsoft site:

Plugin Status
Polaroid Picture Plug-In Works
Insert Code Works
Paste As Visual Studio Code Works well, doesn’t allow changes after you paste.
EzMceWriter For Live Writer Doesn’t work – crashes.  Appears to work for only for older LW.
Table Plugin Ok, pretty basic…

 

Definitely try it out!

John Dorsey
IT Brigade Inc.
www.itbrigadeinc.com

BlogEngine.NET ,

Requiring Comments to be Moderated

11. April 2010

Comments must now be approved - too much spam!

Looked into spam blocking a little, but don't want to spend alot of time on this...

Definitely a weakness for BlogEngine.NET...

 

Update 10/15/2010:

Disabled comments - getting way too much spam!

BlogEngine.NET

Session State setting in BlogEngine.NET

13. March 2010

After a long investigation why a Captcha image wasn't being generated, I discovered that BlogEngine.NET has the session state disabled in web.config.  I am generating a Captcha image via a webpage and storing the text string in a session variable.  I chose to turn the session state back on as this is acceptible for my needs.

Search in web.config for:

enableSessionState="false"

and change it to

enableSessionState="true"

 

BlogEngine.NET , ,

User Control

28. February 2010

This is an implementation of a generic C# contest entry user control (.ascx) which is embedded in a blog entry using the BlogEngine.NET format.

 

For BlogEngine.NET users:

It is easy to enter a user control on a blog page in BlogEngine.NET, just type the following into your blog:

See the following link for more details: User Control Injection in BlogEngine.NET 

 

C# User Control:

The user control shown here is for entering on-line contests.  Validation of the contest entry parameters is done primarily on the client side.   Once validated, the entries are encrypted and then loaded into SQL Server.  I also added a captcha to prevent programs from entering contests (although that doesn’t appear to be working presently).

 

John Dorsey
IT Brigade Inc.
 www.itbrigadeinc.com

 

 

 

 

Enter the Sweepstakes below for your chance to WIN!
Must be 18 to enter
Contest Runs Between 1/6/2012 and 3/6/2012
Gender 
First Name  
Last Name  
Address 1 
Address 2
City  
State 
Zipcode  
Year of Birth  
Home Phone  
Email  
Enter Text     
No purchase necessary to enter or win. See the Official Rules for eligibility requirements and complete details.
 

BlogEngine.NET , , , , ,

Restricting access to certain Blogs

27. February 2010

I wanted to restrict access to certain blogs on this website.

Note: This is not a SECURE solution! - it just limits the blogs to certain users which have the allowed role for a particular category of blogs.

Used the PostSecurity extension solution developed by LavaBlast
http://blog.lavablast.com/post/2008/08/BlogEnginenet-Post-Security.aspx
and further refined by
http://www.bookofkai.com/post/2008/09/20/Well-that-didnt-take-long.aspx
which hides some of the traces of the restricted blogs and allows the Administrator to view everything.

Had to rebuild blog core and website and upload to hosted site.

I am using Sql Server backend - so to add a role to a restrict access to a Category had to go into the SQL Table be_Role.  Add a new role
by typing in role name in the table.  The role id is automatically created.

Then go into the PostSecurity Extension and add the Category and Role.

Then go to users and add the Role to the desired users.

Worked pretty well.

 

Update: 6/16/2011

Turns out the bookofkai.com link no longer works.  If you want the code changes, just email me at jdorsey@itbrigadeinc.com and I’ll send you the changes required.

John Dorsey

IT Brigade Inc.

www.itbrigadeinc.com

BlogEngine.NET ,

I'm using BlogEngine.NET

17. February 2010

I'm blogging with BlogEngine.NET 1.6 which is an open source blogging tool: http://www.dotnetblogengine.net/.   I chose BlogEngine.NET for the .NET framework and C# coding.  Tried DotNetNuke, but that was much more complicated.   I am using a SQL Server backend to store the blog information. 

BlogEngine.NET , ,