Thursday 24 April 2008

Postback opens layout rather than the Sitecore item

This was a weird one. I created a Sitecore item with layout and a sublayout. Then I placed a Button control on the sublayout and adding a click event handler that did something simple like display "Hello World" in a label on the sublayout. However, clicking the button navigated to the layout, rather than posting back to the Sitecore item. A colleague searched the Sitecore forum and eventually sorted the problem. It was due to the following line being commented out in the Form.browser file:
<adapter controlType="System.Web.UI.HtmlControls.HtmlForm"
adapterType="Sitecore.Web.FormAdapter, Sitecore.Kernel" />

I had commented this out due to runtime exceptions I was getting that referred to this line in the file. However, it now seems perfectly happy with it left in!

The file exists in the App_Browsers folder in the web site root. If it isn’t there, copy it from a clean 5.3.1 installation.

[Edited 30/7/2008]

And thanks to my colleague Jason Linham for noting further that the folder should not be hidden.

[Updated 16/9/2008]

Wednesday 23 April 2008

System.OutOfMemoryException during Visual Studio 2008 build

Just recently, Visual Studio 2008 kept failing with a System.OutOfMemoryException when doing a build. The problem seems to have been due to inadequate Windows virtual memory. I upped the value of the paging file and, so far, have had no further exceptions.

... 1 hour later... whoops, spoke too soon. A re-installation is now taking place.

[Edit 2/5/2008: Still no luck. I have noticed that massive amounts of data are generated in the temporary ASP.NET files folder (C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files). The other day, VS created over 3Gb of data in there when building a solution that was only 187Mb in size. Might be part of the problem.]

Wednesday 16 April 2008

Sitecore item content not showing

As I’ve spent too many times trying to work out why item content (or a change to an item) is not reflected in the browser, here’s a quick note-to-self check-list:

  • If the item is in a workflow, check it has been submitted and approved

  • If you’re referencing an item using @key (eg. item[@key='fieldname']), make sure the field name is all lower case

  • Check the item has been published (do a full publish if changes have been made to templates too)

  • Do a full publish (or re-save the web.config file) if you suspect Sitecore caching is having an effect

  • Check the content of the item is in the web database by using the dbbrowser utility (in the same broswer session as your Sitecore instance, browse to /sitecore/admin/dbbrowser.aspx)

  • If you’re using local IIS, do an IIS reset to refresh the cache

  • Use the Access Viewer to check the permissions of the item for the extranet anonymous user

  • Check the item’s rendering is assigned to a valid placeholder key (be particularly careful if you are attaching renderings dynamically)

  • If applicable, view the HTML source and paste into the W3 validator to check for errors. Something like a self-closing script tag can throw the output.


Have I forgotten anything?

[Updated 7 Jan 2009; added bullet]

Friday 4 April 2008

Using ASP.NET Log-in Controls with Sitecore Extranet

It is simple to use the log-in controls to sign in to a Sitecore extranet. Having dragged a Login control to the design surface of a layout or sub-layout (ie. web form or user control), go to the control’s properties and click the lightning symbol. Double-click the field to the right of the Authenticate item to attach an event handler to the Authenticate event. In the event handler, set the Authenticated property of the AuthenticateEventArgs parameter equal to the success flag of the Sitecore Login() method.

Your Login control definition will be similar to:

<asp:Login ID="Login1" runat="server"
OnAuthenticate="Login1_Authenticate"></asp:Login>

Your event handler will be similar to:

protected void Login1_Authenticate( object sender,
AuthenticateEventArgs e )
{
e.Authenticated = Sitecore.Context.Domain.Login(
Login1.UserName, Login1.Password).Success;
}

The user instance login flag is not supported on this version of SQL Server. The connection will be closed.

I got this error this morning when moving from a SQL Express database to SQL Server 2005. The fix was simple: I just needed to remove the "User Instance=True;" in the LocalSqlServer connection string, from:

<add name="LocalSqlServer"
connectionString="Data Source=(local);
Integrated Security=True;User Instance=True;
Initial Catalog=dbname"
providerName="System.Data.SqlClient"/>

to

<add name="LocalSqlServer"
connectionString="Data Source=(local);
Integrated Security=True;Initial Catalog=dbname"
providerName="System.Data.SqlClient"/>