When you run Sitecore 6.x in Integrated Pipeline Mode, You will notice that ALL IIS log entries contain the log entry for the resquest to the layout (aspx) page (instead of the actual sitecore item .e.g /ContactUs.aspx).

If you run Sitecore in Classic Mode, the problem disappears. However, if you still wish to use Integrated Pipeline Mode, you will have to intercept the request before the Sitecore HttpModule (Sitecore.Nexus.dll) gets involved.

Solution

Create a class that extends System.Web.IHttpModule and set the path back to the original value after the request has been processed but before the IIS logging module writes the log entry.

A test Sitecore Application .. I will be using the Sitecore Starter Kit [Sitecore Starter Kit 6.0.0 rev.090203] as an my starting point. (installed on IIS 7).

Before I start on implementing the solution, a little bit of background info would, I guess, be quite useful.

AddAspxExtension in LinkManager

A potential solution is to change the value of AddAspxExtension from true (by default) to false. If you do change it to false, you will have to create a wildcard script map to the ASP.NET runtime. This causes IIS to intercept every request made against the web server. This includes requests for images, asp.net pages and HTML pages. Therefore, enabling a wildcard script map to ASP.NET does have performance implications. If you wish to find another way to use pages without .aspx extensions in Sitecore, please read further....

Sitecore Aliases

Aliases, in a nutshell, allow you to shorten the url of an item. For example, if your item is currently accessible via http://hostname/MyParentItem/MyChildItem.aspx, you can specify an alias of myChildItem, which will be a placeholder for the actual item as it is in the Sitecore tree. Hence, the url of the alias is http://hostname/MyChildItem.aspx. For SEO purposes, this allows us to surface items from deep down in the hierarchy right up to the site root.

Note:

Aliases do not work if you remove the .aspx extension

No matter how far your items are in the sitecore tree, an alias allows you to refer to it from the site root.

Step 1: Install and Configure Helicon ISAPI Rewrite Lite

Start by installing Helicon ISAPI Rewrite. This process is fairly straightforward. Since we are using the lite version, our Regex entries will be placed in the global http.conf (located in the Lite version installation folder). The entries in my httpd.conf are as follow:-

Url Rewriting Rationale

Before a request is forwarded to Sitecore, the ISAPI module intercepts it.

Line 1: You NEED that ! This turns on the Helicon ISAPI Module

Line 2: Errr...This is self-explanatory..

Line 3: We don't need to chop off the .aspx when we are in Sitecore CMS. For this reason, we're basically telling the module to not do anything when a request has "sitecore" in it.

Line 4: This is the most important bit. This appends .aspx (and querystrings,if any) to requests and consequently forwards the resulting request to Sitecore. Two scenarios arise as a result of this.

3.1 : Sitecore maps the request to an item in the database. The page gets displayed in the end.

3.2 : Sitecore cannot find the item based on the url. You will either end up with the Sitecore's "Item Not Found" page.

NB:

Before we go any further, I need to confess that I did modify the Starter Kit a little prior to this operation. Basically, when you load the starter kit, you are greeted with a dummy home Site, that has a nice layout and there is a link to the Actual Starter Site. I was tired of this as my home page, So, I changed the value of "startItem" [in the Sites Definition of website (in web.config)] from "/home" to "/Sample". In that way, when i hit the website, I will eventually land on the real starter site!. Also, by doing so, all my urls within the website will no longer contain "/sitecore/content/.." since the Start Item has changed.

It looks like we have a half-baked solution. Aliases will now work without the .aspx extension as well. The other bits that need to be considered are

1 : How to make sitecore controls (.e.g. sc:link etc..) aware that they should drop the ".aspx" extensions

2 : How does it all tie up together with .NET (user controls etc..)

Step 2: XSL Extensions (revised)

To follow up on custom solution, you will need to tell Sitecore to remove the ".aspx" when it renders urls (either via sc:link [xsl extensions] or c# code). For XSL Extensions, we need to disable the default implementation that Sitecore provides us with and roll out our own. Fortunately, it's very easy to do so. [Credits : Chris Wojciech ]

NEARLY THERE!!!. All the links (that are rendering using sc:link) have now lost the .aspx extensions on the front end.

Step 3 : Sitecore and .NET interaction (with Url Rewriting)

If you have a Sitecore solution built using XSLT renderings only (highly unlikely though..), you're kinda safe here. However, if you have usercontrols (that host controls that can cause a postback) as well (for argument's sake, a contact us form), you end up with one issue.

Let's create a Contact Us form and add it to the presentation of the Contact Us item in Sitecore

Let's face it. Although I'm no designer, I do feel sorry for my fellow colleagues when I hear them complain about the rendering on some specific browser(s).

It gets harder when testing against IE6 for example. They normally use IE6 VMs to perform testing. There are three major drawbacks of this approach:

1: WHERE IS THE IE6 VM? Is it on the local machine? Is it on the network? Is it on a Virtual Server that no one has admin rights to? Does the IE6 VM have a meaningful name .. Imagine having 10 VMs locally and having to boot each one to see if IE6 is present !!

2: Loss of password for Logging into VM. (just because the last person who logged in just decided to change the "usual" password to his/her cat's name and not telling anyone about it..and he/she is most propbably off sick when we need to do testing)

3: VM gets copied across network onto physical machine. Transfering 6-10 GB to your computer and hosting the VM locally. Another designer comes along and does the same thing. We now have 2 VMs on 2 different machines that serve the same purpose. Let's not entertain the idea of having both VMs running simultaneously !! A whole range of IP Address/Name resolution conflicts arise. :)

Microsoft Expression Web SuperPreview for Windows Internet Explorer

This tool allows us to view a page in different IE versions. This eliminates the use of glorious VMs for testing. Well done Microsoft !

"Expression Web SuperPreview for Internet Explorer is a stand-alone visual debugging tool that makes it faster and easier to migrate your sites from Internet Explorer 6 to Internet Explorer 7 or 8. With Expression Web SuperPreview for Internet Explorer, you can ensure that your Web sites work correctly in Internet Explorer 8 while also maintaining compatibility with earlier versions of Internet Explorer.

Expression Web SuperPreview for Internet Explorer shows your web pages rendered in Internet Explorer 6 and either Internet Explorer 7 or Internet Explorer 8, depending on which version you have installed on your machine. You can view the pages side by side or as an onion-skin overlay and use rulers, guides and zoom/pan tools to precisely identify differences in layout. You can even compare your page comp to how the targeted browsers render the page.

Expression Web SuperPreview for Internet Explorer not only shows a high-fidelity rendering of how pages will look on different browsers, but it also identifies the element's tag, size and position, applied styles, and location in the DOM (Document Object Model) tree so you can quickly fix the error. "

Expression Web SuperPreview for Internet Explorer is a standalone, free application with no expiration and no technical support from Microsoft.

Note:

If you wish to have the ability to debug pages both in IE and Firefox flavours in a single application, go for Microsoft Expression Web. You can download a 60-day trial copy here

It's the third time I'm writing on this particular topic (The EncodeNameReplacements element in the web.config). Articles 1 and 2 have had their importance in building SEO-friendly links in Sitecore.

Double Encoding in Urls

Whilst doing some routine administrative tasks in sitecore, I noticed that some links were no longer working. I was pretty sure that those links were working before I did a publish. :( Back to the drawing board.

in my web.config. It was working fine when sitecore items were having names like "Camera one" (->url: camera-one.aspx), "Camera one two three" (->url: camera-one-two-three.aspx) etc...

However, if an item name has a character that has already been defined in my EncodeNamesReplacements section, Sitecore throws you back on the Item Not Found page. In my situation, I had renamed the Sitecore Item :"John Doe" to "John-Doe" (lame administrative task...I KNOW) . The effect of this is that when the user clicks on the John-Doe.aspx, he/she is redirected to the default "Item Not Found" sitecore page. A careful look at the url has revealed that Sitecore was trying to request an item with a name of John--Doe and consequently failed.

Solution

or hack (for some people)

If you are using a specific character to get rid of spaces in url, you need to make sure that a cms user will not be able to create an item name having that character in. Easy way to factor this in is to include your character in the InvalidItemNameChars element in the web.config. In my implementation, I've changed that setting to :

Here's the situation. You are about to implement a password protected area on your website. Let's assume that the general site structure looks like this

Pages below General and Products are accessible to everyone, whereas pages under Members should only be visible to authenticated/logged in members. I will first briefly outline the steps required to get this problem implemented using ASP.NET. Later on, I'll move onto it's equivalent Sitecore Solution.

Using ASP.NET

Implement Forms Authentication and set login url in the web.config.

Implement Login control and decide where to retrieve and store login credentials (in web.config or database)

In the web.config, add a Location Path pointing to the Members folder (Deny anonymous , allow authenticated users )

This is all about it really...(as far as I remember..) ...

In Sitecore, it's a different ball game.

In addition to adding the loginURL to the form authentication section (important if you use the loginview control to show the login page), you will need to add the "loginPage" attribute to the site which is defined by your extranet domain (normally, it's called "website" )

The LoginPage attribute is not something new here..It has always been there..(e.g. the shell website has already a loginPage set), but i did not know what was its purpose . Thanks to Chris Wojciech, I've discovered how to use this existing functionality in the web application.

The addition of Location path in the asp.net-only model is analogous to denying read access to the Members folder (+descendants) in Sitecore.

Once you perform a site publish, you can see the effects straight away.

If you've already signed in, you will be able to view /Members/View My Account.aspx.

If you're an anonymous user and access /Members/View My Account.aspx, you will be presented with a default page that Sitecore serves in case access is denied due to security privileges.

Recommended Solution

The nag in the above quick fix is that sitecore internally adds 3 QueryStrings to the url ( item, user and site). If we compare this to the normal ASP.NET solution, we would have ended up with only 1 querystring, which is the ReturnUrl. Our goal is to follow the asp.net solution as close as possible. This is where Chris comes in..

Rolling out your own Security Resolver

Chris extended the HttpRequestProcessor class in order to intercept the request ,check if the user requesting the sitecore item has appropriate rights. If that is not the case, the user is redirected to the login page, with the appropriate ReturnUrl QueryString. Please go check the code out on his blog at http://blog.wojciech.org/?p=64

The processor should then be plugged in the web.config, before the definition of the ExecuteRequest processor.

LoginView Control Caveat

The LoginView control "magically" knows the login page url. This is specified by the LoginUrl attribute in the FormsAuthentication section of the web.config. This is not to be confused the LoginPage attribute (from the sites section). I had to modify my web.config to

Erractic Behaviour when logging out

I did not experience any problems when logging in .i.e. the control did what is was supposed to do (display sitecore username and Logout Link). HOWEVER, when I pressed the Logout link, I always got redirected the Sitecore Layout page instead. I did spot similar behaviour with ListViews in Sitecore (also documented by Paul George and Mark Cassidy, where its events were not being fired at all. I've made the following change to my web.config and that solved the problem :)

I guess that a value of "00:00:00" for the interval attribute does disable automatic publishing. If you set the value to (say..10 minutes) "00:10:00", you will notice that after 10 minutes or so, changed items from the master database will be copied over to the web database.

Automatic publishing is useful where you have integrated external datasources in sitecore (using Data Providers) and where there needs to be a predefined process that synchs the external data to the web database. For the automatic publishing to work in this particular situation, you must have had created a new database entry (with a reference to your data provider) in the web.config.

Scenario

Assume that you have a set of items (say..Product items) (sitting anywhere within the /sitecore/content..) based on a specific template. The requirement here is that

"A Product cannot be published if one of its fields (ProductID) isn't populated."

Background

To achieve this, we need to hook into the publish:itemProcessing event in the web.config. This event gets triggered every time an item is published. The general steps involved in this situation are:

Create a class with a method that adheres to the EventHandler delegate signature. Whenever you initiate a publish operation in sitecore (be it smart publish, incremental or full publish), the method will be called (depending on how many items that need to be published)

Line 7: Cast the standard EventArgs class to ItemProcessingEvent. This is important since it gives you the possibility of retrieving details of the items being published.

Line 9: Retrieve the item being published.

Line 11: The check for "currentItem.Paths.IsContentItem" is important since we only want to check for content items. Since publishable items sitecore vary from templates,standard values, renderings... we do not want to check for the condition in ALL items.

Line 14: If the template of the current item matches the id of the Product template, then we're back in business.

Line 16 - 21: Find the reference to the current Job (and JobStatus) being executed in the publish pipeline. If the item's field is empty, add a message to the JobStatus.

Line 22: Abort the publish operation of the current item. I don't think we require the return statement after that. Publishing will then resume for the next item in the publishing queue.

Web.Config Change

Locate the publish:itemProcessing event in the web.config. Hook up the new handler to the event.

Let's put it to the test

That's all to it really. If you now initiate a publish operation and one of the Products has an emtpy Product ID, you will end up with this (if you click on "Click here to see additional information" on the last screen of the publish wizard.)

Items Skipped = 1 (.i.e Camera item has been skipped during the publish process since it has no ProductID). If you switch to the web database, there will not be any "Camera" item.

Result... :)

4 months since my last post. This should give you an idea of my hectic life as a software developer. Build..Test.. Deploy.....Build..Test.. Deploy.. This seems to be the only thing that I have been doing lately and hasn't left me with any time to do anything else.

Things have got to change and NOW is the time :-)

Back in Febuary, I came accros a file (via some random Google Search about Sitecore) that outlined some good one-liners about building websites using Sitecore. At that time, I added the link to my favourites and didn't pay much attention to it. Now that I've accessed the link again (by mistake..), I realise that so many of those "guidelines" are correct. Unfortunately, I did not capture the author of the text file at that time. Here's the online version

The Sitecore Way

1) Think about the CMS users not just the Web site. The Sitecore Way.

2) Use XSLT to minimize code compilation for maintenance. The Sitecore Way.

3) Get better performance with ASP.NET user-controls. The Sitecore Way.

4) Use an ASP.NET master for your layouts. The Sitecore Way.

5) Return Item ID for XSLT extension results. The Sitecore Way.

6) Avoid setting language in a request after the Sitecore pipeline. The Sitecore Way.

7) Use icons for your masters and templates. The Sitecore way.

8) Protect /sitecore as much as you can. The Sitecore way.

9) Cookieless is possible, but be careful. The Sitecore way.

10) It's very important to Organize the content structure correctly. The Sitecore Way.

11) Finalize design as much as you can before implementation. The Sitecore way.

12) Ask for design behavior specs not just content info. The Sitecore way.

13) Use file system for large files instead of media library. The Sitecore way.

This post will most probably apply to the GridView and LoginView controls as well.

The Problem

Lets assume that you've successfully bound a listview to your datasource and configured all the properties on the listview to display the Select/Edit/Delete links. You then have the task to write the logic in the appropriate events of the usercontrol/sublayout. While I was implementing the Edit functionality, I implemented the OnItemCommand event of the Listview to display an Edit Panel with the data populated from the selected row. I was a bit suprised to see that the end result wasn't what I was expecting:

The Edit Panel shows up but the Listview has left the party.!!

The Frustration

It dawned on me that, at some point, I must have messed up somewhere in the code.So, I began putting "EnableViewState=true" to every control.. (this shows how desperate I was!!). I also reverted to "AutoEventFireUp=false" (Originally, I was manually hooking up the events..).I tried databinding on every possible method I could lay my hands on!!. I lost confidence on the fact that this was a really easy task and yet, it was taking me hours to get to the bottom of the problem. I completely lost my mind....I began googling on the issue ["postback..losing viewstate"], I started to watch a few videos that demonstrate the functionality of the ListView..I even got the point where I created another item in Sitecore, assigned the same sublayout to the item's presentation and accessed the item using the url.. I ended up in the same situation.... I surrendered...I left the battlefield...wounded..!!![White flag..].

The Solution

I finally blamed it on Sitecore!! Who knows, maybe it was a known issue in one of their releases or maybe I just needed to upgrade to the latest stable release(090120). Out of desperation, I tried searching on the Forums and found that I wasn't the only one experiencing this issue.I came across this forum post. Thanks to Mark Cassidy, I eventually finished my task (It had taken me almost a day...and that had messed up (big time) on my initial estimate!!!)

The solution, as Mark outlined, is to add the type of the control (in my case, System.Web.UI.WebControls.ListView) to the typesThatShouldNotBeExpanded element in the web.config. Presumably, for the sake of consistency, you might also append the System.Web.UI.WebControls.Gridview to the list (in case your website makes use of one!!). From what I've read so far, no one knows about the purpose of the typesThatShouldNotBeExpanded element .!! {Sigh...Sitecore!! What did you do that to me????}