clean urls on posts

Topics: ASP.NET 2.0
Jan 12, 2012 at 9:04 PM

I am using BlogEngine.Net 2.0 hosted on IIS6 box.  I am using some rewrite rules via an add-on to drop the aspx extension and then 301 to page without extension.  An example would be /Contact.aspx 301's to /Contact.  The dropping off extensions seems to work everywhere except on the posts.  The ASPX extension gets dropped because of a rewrite rule from the page name and then 301's to a 404 page not found.

Questions:

  1. I get there is some kind of a rewrite happening that sends all posts to the posts directory with title but what is that process?
  2. What can i do to get the posts to resolve without the aspx extension(a clean url soution for the posts)?
Coordinator
Jan 12, 2012 at 9:28 PM

1. UrlRewrite module in the core library.

2. This fork does it, but need a lot of testing/reviewing and currently pending. Might work for you though.

Jan 13, 2012 at 3:43 PM

Thanks for your quick reply rtur.  I will download and test and let you know how it goes.

Jan 13, 2012 at 4:11 PM

Downloaded solution from fork.  Unzipped download and put everything from the BlogEngine.Net folder into web directory and am now getting a compilation error on default page of:

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0246: The type or namespace name 'BlogEngine' could not be found (are you missing a using directive or an assembly reference?)

Source Error:


Line 4:  namespace App_Code.Controls
Line 5:  {
Line 6:      using BlogEngine.Core.Web.Controls;
Line 7:      using BlogEngine.Core.Web.Extensions;
Line 8:  


Source File: c:\Inetpub\wwwroot\hairdesignBlog\App_Code\Extensions\SimpleCaptcha\SimpleCaptcha.cs    Line: 6

 

Please advise.

Coordinator
Jan 13, 2012 at 4:51 PM

Check if you have BlogEngine.Core.Dll in the /bin folder. Source code does not have binaries included, you need to build it in VS or web developer express and use cored DLL resulted from that build for your website.

Jan 13, 2012 at 5:12 PM

used bin folder from last full download and put into directory and now getting:

Server Error in '/' Application.

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0103: The name 'BlogConfig' does not exist in the current context

Source Error:


Line 155:                var anc = new HtmlAnchor
Line 156:                    {
Line 157:                        HRef = string.Format("{0}author/{1}{2}", Utils.RelativeWebRoot, user.UserName, BlogConfig.FileExtension),
Line 158:                        InnerHtml = string.Format("{0} ({1})", user.UserName, postCount),
Line 159:                        Title = string.Format("Author: {0}", user.UserName)


Source File: c:\Inetpub\wwwroot\hairdesignBlog\App_Code\Controls\AuthorList.cs    Line: 157


Jan 13, 2012 at 5:27 PM

Just another quick note is that I am using bin folder from a download of v2.0 of BE.  Also the entire project now consists of the entire download from the fork and the bin folder from the 2.0 download.  Every time i refresh home page of blog i get same error about BlogConfig but in different locations.

Jan 13, 2012 at 5:33 PM

Try to add this reference at the top of your code (AuthorList.cs) -->>

using BlogEngine.Core;

Jan 13, 2012 at 5:43 PM

above fixed error on authorlist but now getting the following error even though these pages do have references to BlogEngine.Core

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0117: 'BlogEngine.Core.Utils' does not contain a definition for 'ShouldForceMainTheme'

Source Error:


Line 52:         protected override void OnClick(EventArgs e)
Line 53:         {
Line 54:             Boolean isForced = Utils.ShouldForceMainTheme(Page.Request);
Line 55: 
Line 56:             if (isForced)


Source File: c:\Inetpub\wwwroot\hairdesignBlog\App_Code\Controls\MobileThemeSwitch.cs    Line: 54


Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0103: The name 'BlogConfig' does not exist in the current context

Source Error:


Line 125:                                InnerHtml = day.DayNumberText,
Line 126:                                HRef =
Line 127:                                    string.Format("{0}{1}/{2}/{3}/default{4}", Utils.RelativeWebRoot, day.Date.Year, day.Date.ToString("MM"), day.Date.ToString("dd"), BlogConfig.FileExtension)
Line 128:                            };
Line 129:                        a.Attributes["class"] = "exist";


Source File: c:\Inetpub\wwwroot\hairdesignBlog\App_Code\Controls\PostCalendar.cs    Line: 127


Show Detailed Compiler Output:

Show Complete Compilation Source:

and a different error every time I refresh from most of the files located in the App_Code folder.

Jan 13, 2012 at 6:22 PM

Make sure the MobileThemeSwitch.cs has these references

    using System;
    using System.Web;
    using System.Web.UI.WebControls;
    using BlogEngine.Core;

 

and PostCalendar.cs has these

 

    using System;
    using System.IO;
    using System.Linq;
    using System.Text;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using BlogEngine.Core;


Coordinator
Jan 13, 2012 at 6:49 PM

You can't use 2.0 core DLL with latest website source code, they are not compatible. You'll get errors all over the place. It has to be DLL built from source you downloaded.

Jan 13, 2012 at 6:57 PM

rtur is right...

Jan 13, 2012 at 7:31 PM

not familiar with building the binaries from scratch. I am using VS2008.  How would i do that?

Jan 13, 2012 at 7:59 PM

In other words how can build the dll's I need for BE from what i downloaded from fork?

Coordinator
Jan 13, 2012 at 8:21 PM

It probably won't work with 2008, latest code is .net 4.0 and you can build it with free web developer express 2010:

1. Double click solution file "BlogEngine.sln" to open in VS or web developer, whichever you'll be using.

2. In the solution explorer, right-click BlogEngine.NET project and select "set as startup project".

3. Select "debug/build website" from the top menu.

Should build with no errors and create all required DLLs in the /bin folder.

Jan 16, 2012 at 4:58 PM

Did as suggested above - built out project in VS2010 express which built out dlls.  What is the next step in enabling clean urls for posts?  Does this also allow for clean urls throughout other pages or is there something else that needs to be done?

Coordinator
Jan 17, 2012 at 1:54 AM

That's it, should be no other steps. Just run and see if it will work. If you can use something like "http://mysite.com/blog/the-post-title" than it does the job.

Jan 17, 2012 at 6:43 PM

Thanks for all of your quick replies, rtur.

Ran blog in browser as is and the links generated are same as before (ex.post/2011/06/23/Post-Title.aspx)  Do I need to create an htaccess rule or is the rewrite module suppose to write the url's w/o the extensions for me?  Also, is it possible to create a directory structure like blogs/x/2011/06/23/Post-Title where x can be any one of several different directories?  If so, what do you recommend to accomplish this?

Coordinator
Jan 17, 2012 at 10:37 PM

Unless you running BE on Apache (using Mono) htaccess rules will be ignored by IIS. UrlRewrite module can let you change URL structure, but I'm confused why would you need to do it this way? BE supports multiple blogs on single install, so you can have yoursite.com/blog1/2011/06/23/your-post and yoursite.com/blog2/2011/07/24/another-post and so on.

Jan 19, 2012 at 5:01 PM
Edited Jan 19, 2012 at 6:26 PM

URL's are rendering as before(ex.post/2011/06/23/Post-Title.aspx).  There does not seem to be a change in structure.  The extension is still part of the url.  FYI - The footer of homepage displays:

Powered by Blogengine.net 2.0.0.45

Is this right? The version seems like it should 2.5?
Is there anything else I need to do to have clean url's?