Wednesday, December 7, 2011

Sitecore Context Item is not the expected item

Few days ago, I encountered a puzzling problem where the Sitecore Context Item is returning an Item from different webroot of another languge.

So for example,

Sitecore
* Content
** English
*** Item one
** China
*** Item one

When I am on Sitecore/Content/China/Item one, I would expect Sitecore Context Item to return Sitecore/Content/China/Item one. However strangely, it was returning Sitecore/Content/English/Item one.

The first thing I look was HttpRequestPipelines to see if any custom code cause this problem. However none of it, is the problem.

One of my colleague found the issue, it was to do with an Alias that was setup. Normally this will not cause a problem, because normally when we create an Alias we will use a different name from the item name.

Unfortunately the scenario that I faced previously was; Alias to the item with the item name itself.

i.e. (Alias) : Item One -> Sitecore/Content/English/Item one

This is the cause of the problem, because by default Sitecore Alias did not take into account Language variant and it shares Alias across the Site.

This means, when you type in http://mydomain.com/cn/item one, it will show content that is found on http://mydomain.com/en/item one.




Thursday, November 17, 2011

Sitecore Item default fieldname

Hi Sitecore Devs,

Just thought of sharing the list of Sitecore item default field name (see the imagess below). I believe you can find the listing in a page or pdf somewhere in SDN, but it could be hard to find.

Anyway, if for example you would like to retrieve an item "created by" value

You can do so by

Var createdBy = Sitecore.Context.Item[“__created by”];

Or

Var createdBy = Sitecore.Context.Item[Sitecore.Data.Fields.FieldIDs.CreatedBy];

The later approach by using Sitecore.Data.Fields.FieldIDs. is neater however it does not list the full Sitecore item default field name.



Wednesday, November 16, 2011

Sitecore User Manager is blank (showing gray background with no controls)

Today, I encountered an issue where the user manager in Sitecore was not displaying anything. The only thing that was visible in Sitecore backend was gray backgrounds with no controls.

I asked my colleague and he suggested to replace bin and Sitecore files with the same version of vanilla(fresh) sitecore bin and files.

Done that and cleared the cache however the problem persisted. So next the next thing I did, was to check if the domain has been listed in IE trusted site list. Apparently, the domain was not added to the list. Once I have added the domain to the list, Sitecore backend works as per normal.

The IE version I use was IE9.

Debugging Sitecore 404

Recently, I was baffled with Sitecore throwing 404 error page. This makes things even more so confusing with the following status/checklist

1. Site used to run
2. There is no code changes. The only change was domain name
3. IIS Binding has been configured with the new domain
4. Site is up and domain has been pointed to the correct webroot. I tested this by dumping test.txt on webroot and try to access it by /test.txt. I can get the text file.
5. Changes also have been made on Site definition to relect the new change in domain name
6. Sitecore backend can be accessed
7. I have checked the item exist in backend

Finally i figured out the problem when i inspected the url for the 404. It looks something like below

http://domain.com/Standard-Items/Error-Pages/Page-Not-Found.aspx?item=%2f&user=sitecore%5cAnonymous&site=scheduler

As you can see, the query string "site" is scheduler. That's not right, it should be "website". So I look at site definition again for error

Tuesday, October 25, 2011

RTE not displaying links as GUID

Often we encounter issue where Sitecore Link in RTE is presented in GUID instead its SEO friendly URL. Sitecore by default do render Sitecore Link in RTE in GUID, this is so as to allow movement of the targeted item within the content tree without the need to change the RTE itself. Fortunately Sitecore OOB also support the functionality to convert this GUID link to its SEO friendly URL.

There are two ways to achieve this,

1. Using sc:html instead for example sc:text
2. Using the following code global::Sitecore.Links.LinkManager.ExpandDynamicLinks(value, true);

I personally prefer the first approach whenever possible just because it involves the least amount of coding work.

Monday, October 17, 2011

Microsoft SQL Server Error 18456 Severity 14 State 1

Just then, i have encountered a puzzling error about a newly created login user that I have just created in database. For some odd reason, i keep getting login error even though i have checked that both username and password is correct.

It turned out that the SQL Server is not setup properly. The security setup in SQL server was set to "windows authentication" only where it is supposed to be both "SQL and Windows authentication".

to enable this, right click the SQL Server, click properties, under security tab you will see the radio button. Select "SQL Server and Windows Authentication mode"

Remember to restart the SQL Server as the changes will not take effect before a reboot. To reboot, right click SQL Server -> Restart

Tuesday, August 2, 2011

Custom error for arbitrary extension

Recently I need to present a custom error for webpages with arbitrary extension.

e.g. http://domain/test.blah

Normally it will just present you with a default error message just like the one below

The page cannot be found

The page you are looking for might have been removed, had its name changed, or is temporarily unavailable.
Please try the following:

Make sure that the Web site address displayed in the address bar of your browser is spelled and formatted correctly.
If you reached this page by clicking a link, contact the Web site administrator to alert them that the link is incorrectly formatted.
Click the Back button to try another link.
HTTP Error 404 - File or directory not found.
Internet Information Services (IIS)

Technical Information (for support personnel)

Go to Microsoft Product Support Services and perform a title search for the words HTTP and 404.
Open IIS Help, which is accessible in IIS Manager (inetmgr), and search for topics titled Web Site Setup, Common Administrative Tasks, and About Custom Error Messages.

we want to capture this error and present them with our custom not found page. This requirement is useful if you want to track how many not found page users encounter.
to achieve this the following is entered in the web.config

<httpErrors errorMode="Custom">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="http://www.visitvictoria.com/not-found.aspx" responseMode="Redirect" />
</httpErrors>

just before

</system.webserver>

Tuesday, July 12, 2011

Clicking "Lock and Edit" throws Item archive error has occured

Recently i have been baffled to figure out why clicking "lock and edit" throws an "Item Archive error has occured: Object reference not set to an instance of an object"

The problem is because of the Security setup. Now the Sitecore Tree setup which we inherit from another company is quite messy. Here is the structure


Sitecore
--> Content
--> Home (aka main website)
--> Page 1
--> Mini Website
--> Page 1
--> Another Mini Website

We have a requirement whereby a user let's called him user1 is allowed only to look at "Mini Website". Of course the approach is to use default Sitecore Security feature. Ideally when user1 is logged in the Sitecore tree should look like below

Sitecore
--> Content
--> Mini Website
--> Page 1

That's the cause of the error. Basically Sitecore->Content->Home need to be available.

So the Tree setup turn out to be


Sitecore
--> Content
--> Home
--> Mini Website
--> Page 1

Friday, July 8, 2011

Script to Deploy Files to Delivery

@ECHO OFF
SETLOCAL

::******************************************* Constants / ROBOCOPY Settings ***********************************************************

SET _what=/COPYALL /E
:: /COPYALL :: COPY ALL file info
:: /B :: copy files in Backup mode.
:: /SEC :: copy files with SECurity
:: /MIR :: MIRror a directory tree
:: /E :: Copy Subfolders, including Empty Subfolders.

SET _options=/R:0 /W:0 /TS /FP /IS
:: /R:n :: number of Retries
:: /W:n :: Wait time between retries
:: /LOG :: Output log file
:: /NFL :: No file logging
:: /NDL :: No dir logging
:: /IS :: Include Same, overwrite files even if they are already the same. Use this options if you want to overwrite
:: /XO :: eXclude Older - if destination file exists and is the same date or newer than the source - don't bother to overwrite it.

SET _timestamp=%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%%TIME:~0,2%%TIME:~3,2%
:: This will create a timestamp like yyyymmyyhhmm.

SET _source="X:\source\Deployment\Deploy Me"
:: Source of the files to copy from

::*************************************** End of Constants / ROBOCOPY Settings ********************************************************

:: Delivery 1
SET _dev1="\\delivery1\c$\inetpub\dev.website.com\Website"
SEt _dev1log="X:\delivery1\Deployment\Deployment Logs\APP01"\%_timestamp%.txt

Echo Synchronising Delivery Server 1 with CMS Server
ROBOCOPY %_source% %_dev1% %_what% %_options% /LOG:%_dev1log%
Echo Synchronising to Delivery Server 1 has been completed!
:: End of Delivery 1

Echo.

:: Delivery 2
SET _dev2="\\delivery2\c$\inetpub\dev.website.com\Website"
SEt _dev2log="X:\delivery2\Deployment\Deployment Logs\APP02"\%_timestamp%.txt

Echo Synchronising Delivery Server 2 with CMS Server
ROBOCOPY %_source% %_dev2% %_what% %_options% /LOG:%_dev2log%
Echo Synchronising to Delivery Server 2 has been completed!
:: End of Delivery 2

::***************************************** Archive Settings **************************************************************************
SET _archiveDest="X:\Some Folder\Deployment\Archive"\%_timestamp%
SEt _archivelog="X:\Some Folder\Deployment\Archive\Logs"\%_timestamp%.txt

SET _ArchiveWhat=/MOVE /E /COPYALL
:: /COPYALL :: COPY ALL file info
:: /B :: copy files in Backup mode.
:: /SEC :: copy files with SECurity
:: /MIR :: MIRror a directory tree
:: /E :: Copy Subfolders, including Empty Subfolders.

SET _ArchiveOptions=/R:0 /W:0 /XO /LOG:%_archivelog%
:: /R:n :: number of Retries
:: /W:n :: Wait time between retries
:: /LOG :: Output log file
:: /NFL :: No file logging
:: /NDL :: No dir logging
:: /IS :: Include Same, overwrite files even if they are already the same. Use this options if you want to overwrite
:: /XO :: eXclude Older - if destination file exists and is the same date or newer than the source - don't bother to overwrite it.
::************************************** End of Archive Settings **********************************************************************
Echo.
Echo Archiving "Deploy Me" folder

ROBOCOPY %_source% %_archiveDest% %_ArchiveWhat% %_ArchiveOptions%
md "X:\Some Folder\Deployment\Deploy Me"

Echo Archive complete!
pause

Script to Synchronise Author with Delivery

@ECHO OFF
SETLOCAL

::******************************************* Constants / ROBOCOPY Settings ***********************************************************

SET _what=/COPYALL /E
:: /COPYALL :: COPY ALL file info
:: /B :: copy files in Backup mode.
:: /SEC :: copy files with SECurity
:: /MIR :: MIRror a directory tree
:: /E :: Copy Subfolders, including Empty Subfolders.

SET _options=/R:0 /W:0 /TS /FP /XO
:: /R:n :: number of Retries
:: /W:n :: Wait time between retries
:: /LOG :: Output log file
:: /NFL :: No file logging
:: /NDL :: No dir logging
:: /IS :: Include Same, overwrite files even if they are already the same. Use this options if you want to overwrite
:: /XO :: eXclude Older - if destination file exists and is the same date or newer than the source - don't bother to overwrite it.

SET _timestamp=%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%%TIME:~0,2%%TIME:~3,2%
:: This will create a timestamp like yyyymmyyhhmm.

SET _source="C:\inetpub\source\Website"
:: Source of the files to copy from

SET _ExcludeDir= /XD App_Browsers App_Data data temp upload
SET _ExcludeFile= /XF *.specific.config ConnectionStrings.config web.config

::*************************************** End of Constants / ROBOCOPY Settings ********************************************************

:: Delivery 1
SET _dev1="\\delivery1\c$\inetpub\dev.website.com\Website"
SEt _dev1log="X:\delivery1\Deployment\Deployment Logs\APP01"\%_timestamp%.txt

Echo Synchronising Delivery Server 1 with CMS Server
ROBOCOPY %_source% %_dev1% %_what% %_options% %_ExcludeDir% %_ExcludeFile% /LOG:%_dev1log%
Echo Synchronising to Delivery Server 1 has been completed!
:: End of Delivery 1

Echo.

:: Delivery 2
SET _dev2="\\delivery2\c$\inetpub\dev.website.com\Website"
SEt _dev2log="X:\delivery2\Deployment\Deployment Logs\APP02"\%_timestamp%.txt

Echo Synchronising Delivery Server 2 with CMS Server
ROBOCOPY %_source% %_dev2% %_what% %_options% %_ExcludeDir% %_ExcludeFile% /LOG:%_dev2log%
Echo Synchronising to Delivery Server 2 has been completed!
:: End of Delivery 2

pause

Thursday, July 7, 2011

Sitecore Encrypting Connection String and etc

Recently, I was asked to encrypt connection strings. Here are the codes

Encrypting
----------
@ECHO OFF
ECHO Encrypting web.config connectionStrings ...

SET target="C:\inetpub\folder\Website"

C:\Windows\Microsoft.NET\Framework64\v2.0.50727\aspnet_regiis -pef "system.web/membership" %target%
C:\Windows\Microsoft.NET\Framework64\v2.0.50727\aspnet_regiis -pef "system.web/roleManager" %target%
C:\Windows\Microsoft.NET\Framework64\v2.0.50727\aspnet_regiis -pef "system.web/profile" %target%
C:\Windows\Microsoft.NET\Framework64\v2.0.50727\aspnet_regiis -pef "system.web/machineKey" %target%
C:\Windows\Microsoft.NET\Framework64\v2.0.50727\aspnet_regiis -pef "connectionStrings" %target%

ECHO Finished Encrypting web.config connectionStrings...
pause

Decrypting
----------

@ECHO OFF
ECHO Decrypting web.config connectionStrings ...

SET target="C:\inetpub\folder\Website"

C:\Windows\Microsoft.NET\Framework64\v2.0.50727\aspnet_regiis -pdf "system.web/membership" %target%
C:\Windows\Microsoft.NET\Framework64\v2.0.50727\aspnet_regiis -pdf "system.web/roleManager" %target%
C:\Windows\Microsoft.NET\Framework64\v2.0.50727\aspnet_regiis -pdf "system.web/profile" %target%
C:\Windows\Microsoft.NET\Framework64\v2.0.50727\aspnet_regiis -pdf "system.web/machineKey" %target%
C:\Windows\Microsoft.NET\Framework64\v2.0.50727\aspnet_regiis -pdf "connectionStrings" %target%

ECHO Finished Decrypting web.config connectionStrings...
pause

Thursday, June 23, 2011

Making Http to redirect to Https

There are few ways to achieve this, like through codes and creating another IIS instance to point to HTTPs enabled IIS instance. However all of these approach is not elegant.

There are a way to achieve this, here is the checklist

1. IIS 7 installed
2. Microsoft URL Rewrite Module installed
3. Create HTTPS bindings to your IIS website and assign certificate
4. Ensure Require SSL is NOT checked under SSL Settings for your website

lastly the config changes in web.config.

Link is http://www.iis-aid.com/articles/how_to_guides/redirect_http_to_https_iis_7















Wednesday, June 22, 2011

Exception: System.UnauthorizedAccessException Message: Access to the registry key 'Global' is denied. Source: mscorlib

To add the user a different way:

Go to the Start menu in Windows 7.
Type "Edit Users" in the search box.
Open "Edit Local Users and Groups".
Go to the groups folder.
Right-click on the "Performance Monitor Users" group and go to properties.
Click the Add... button.
Type in "IIS APPPool\DefaultAppPool" and click Check Names.
Click OK and you should be good to go.

Rather than the net localgroup "Performance Monitor Users" defaultapppool /add

Copy Pasting Config files under App_Config cause the website to throw Null Ref Exception

Server Error in '/' Application.
________________________________________
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
Sitecore.Diagnostics.Log.Error(String message, Exception exception, Type ownerType) +132
Sitecore.Diagnostics.Log.Error(String message, Type ownerType) +45
Sitecore.Configuration.Factory.LoadAutoIncludeFiles(ConfigPatcher patcher, String folder) +682
Sitecore.Configuration.Factory.LoadAutoIncludeFiles(XmlNode element) +77
Sitecore.Configuration.Factory.GetConfiguration() +230
Sitecore.Diagnostics.LoggerFactory..cctor() +67

[TypeInitializationException: The type initializer for 'Sitecore.Diagnostics.LoggerFactory' threw an exception.]
Sitecore.Diagnostics.Log.Error(String message, Exception exception, Type ownerType) +84
Sitecore.Diagnostics.Log.Error(String message, Type ownerType) +45
Sitecore.Configuration.Factory.LoadAutoIncludeFiles(ConfigPatcher patcher, String folder) +682
Sitecore.Configuration.Factory.LoadAutoIncludeFiles(XmlNode element) +77
Sitecore.Configuration.Factory.GetConfiguration() +230
Sitecore.Configuration.Factory.GetConfigNode(String xpath, Boolean assert) +86
Sitecore.Configuration.Factory.GetConfigNode(String xpath) +29
Sitecore.Resources.Media.UploadWatcher.InitializeIgnoreList() +100
Sitecore.Resources.Media.UploadWatcher..cctor() +51

[TypeInitializationException: The type initializer for 'Sitecore.Resources.Media.UploadWatcher' threw an exception.]

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck) +0
System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache) +86
System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache) +230
System.Activator.CreateInstance(Type type, Boolean nonPublic) +67
System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) +1051
System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) +111
System.Web.Configuration.Common.ModulesEntry.Create() +39
System.Web.HttpApplication.BuildIntegratedModuleCollection(List`1 moduleList) +156
System.Web.HttpApplication.GetModuleCollection(IntPtr appContext) +1219
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +97
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +188
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +295
System.Web.HttpApplicationFactory.GetPipelineApplicationInstance(IntPtr appContext, HttpContext context) +56
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +231

[HttpException (0x80004005): Exception has been thrown by the target of an invocation.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +8909915
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +85
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +333


Just today as part of config files sync, I have migrated config files across environment, however after I have migrated config by means of copy pasting the file (i.e. rather than opening up editor and copy pasting content). it cause the website to go down. The error is as shown below.

I have tried to
1. Restoring the backup config files (i thought the config files that cause this issue) That doesnt fix it.
2. Restart IIS
3. Restart apppool
4. Reassigning security settings

All of the above doesnt work. So i decided to create brand new IIS Instance and point the physical path to the webroot (with the config changes implemented).

it works!! I conclude somehow the IIS/Apppool must have gone crazy A.K.A corrupted.

However there are times we have implemented lots of setting to the IIS Instance (e.g. whitelisted IPs, SSL certificate, header expiry). it will be a pain to set this up again. Luckily i didnt just delete the old IIS instance. So I try to narrow down the cause of the issue, i try to point the old IIS instance Apppool to the newly created APPPool, and viola it also works! So now i know something must have gone wrong in APPPool. I try to play around with the old APPPool, but in the end i recreate the APPPool with the same name and now it works just like per normal.

Friday, June 17, 2011

MultiEnvironment Setup (1 Content Author + 3 Content Delivery) not clearing cache


Recently, I have been struggling trying to find a solution to a problem whereby Sitecore MultiEnvironment setup is not clearing cache in Content Delivery upon publishing from Content Author.

The setup for this Sitecore project is as above. I eventually contacted Sitecore support for help to troubleshoot this issue. After several days of back and fourth email, we managed to fix the issue! The cause of this problem is ForwardingSecurityEvents.config, i turn this on initially when trying to forward security events. However as our CD doesnot requires any login, this is now deemed as unncessary. So I rename to ForwardingSecurityEvents.config.example From this i learned a few things,

1. in ForwardingSecurityEvents.config, there is a setting false which cause the events to be ignored.
2. clear cache works for all CD IIS isntance even though they are sharing the same CD database

Friday, June 10, 2011

Configuring Production server

http://sdn.sitecore.net/upload/sdn5/developer/configuring%20production%20environments/configuring%20production%20environments.pdf

A really good article on how to configure production server

Thursday, June 9, 2011

SQL Login failed for user

Today, I have come across a strange issue whereby connection to SQL DB is not valid from connection string but it the login is fine through SQL Management Studio.

The error i have received is as such;

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'user'.

To solve this issue, I have forced any connection to SQL Server to use TCP/IP. this is done by disabling all other protocol (e.g. Name Pipes and Shared Memory) using SQL Server Configuration.

Note: the SQL Database is clustered, which adds to the complexity.

Monday, May 30, 2011

Item Saving Pipeline change field trigger infinite loop

Recently, my colleague is required to duplicate a field value to another field. let's just say Publish To field. To do this it will need to create a custom pipeline processor on item saving. However we face a problem of infinite loop, because after changing the field value, it triggers the on item saving pipeline again. To solve this issue,

we need to set

item.Editing.EndEdit(true);

after editing the field.

Sunday, May 29, 2011

Sitecore Query

I have come to known this issue whereby Sitecore Query limit the search by default to 100. This means potentially we will get less results than expected. Recently, I have come across a solution where the Query max item is tweaked on the fly.

here is the sample code


///
/// Set Query.MaxItems unlimit
/// Reference : http://blog.bylectric.net/2009/07/sitecore-and-query-maxitems-setting/
///

///
///
///
public static Item[] QueryItemsWithoutLimit(string queryString , Item startRoot )
{
if (string.IsNullOrEmpty(queryString) || startRoot == null)
return null;

Query query = new Query(queryString);
query.GetType().GetField("m_max", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(query, 0);
Object result = query.Execute(startRoot);
QueryContext qc = result as QueryContext;
QueryContext[] qcArray = result as QueryContext[];

var database = global::Sitecore.Context.ContentDatabase ?? global::Sitecore.Context.Database;
if (qcArray != null && qcArray.Length > 0)
{
Item[] itemArray = new Item[qcArray.Length];
for (int i = 0; i < qcArray.Length; i++)
{
itemArray[i] = database.Items[qcArray[i].ID];
}
return itemArray;
}

if (qc != null)
return new Item[] { database.Items[qc.ID] };
return null;
}

Thursday, May 19, 2011

Cache a File and clear it when the file changes

There is a few to achieve this objective, one of the way to do this is by using

FileWatcher class.

however there is an easier approach to do this by using CacheDependency. here is a sample code

Cache.Insert("Name", myArrayList, New CacheDependency("C:\Images")
Cache will update itself if any files are added, deleted, or edited.

ref: http://www.velocityreviews.com/forums/t92933-cache-dependency-question.html

Wednesday, May 11, 2011

Migrating Legacy URL to New URL while maintaining SEO Ranking

Recently, I was asked to solve the issue of maintaining SEO ranking for an existing website that has a new IA implemented. Basically, to achieve this, we need to redirect the old IA which maybe obsolete/not existent to its corresponding IA. For this we have a map of old to new IA/Url.

There are a few ways to tackle this, one way is to write a processor that reads the url and check that against a config file for its corresponding new IA/url. however I may have found a more elegant solution by using Microsoft URLRewrite modules. Some links that I found useful

1. http://www.iis.net/download/URLRewrite
2. http://stackoverflow.com/questions/1173299/rewritemaps-with-an-external-config-to-force-an-application-pool-recycle

There is a potential leveraging this to make a Sitecore module which helps with one to one url mapping of old to new pages. This can be done by creating a "OldUrl" field for each item, with this data we can then create a Config file with old to new pages mapping which can then be fed to URLRewrite module.

ref: http://sitecorejohn.wordpress.com/2010/03/24/cmswire-microsoft-offers-seo-friendly-urls-with-url-rewriter/

Thursday, April 28, 2011

JSON.Net CamelCasing Property Name

By Default when we serialize an object to a json string format, it will use the object property name along with its case. I.e. if i have a property named "MyString" = "TestString" the json format will be

{"MyString":"TestString"} however sometimes we want to have the property name to be camel casing like

{"myString":"TestString"}

Here is how to do it:JsonConvert.SerializeObject(obj, Formatting.None,
new JsonSerializerSettings
{ContractResolver = new CamelCasePropertyNamesContractResolver()})

References:http://stackoverflow.com/questions/2789593/force-lowercase-property-names-from-json-in-asp-net-mvc

JSON.Net Custom rule to serialize property

I faced a problem where I need to not serialize to Json a Property when the Property is either empty string or zero.

I have Json.Net library which can be download here http://json.codeplex.com/. Very robust library. I highly recommend using it when dealing with Json string.

Anyway, back to the issue, to solve this problem, we create a method on the class itself with the following prefix "ShouldSerialize" + "". So for example if the property name is MyString, the method would be like the following

public bool ShouldSerializeMyString()
{
return !string.IsNullOrEmpty(MyString);
}

References:
http://james.newtonking.com/

Tuesday, April 19, 2011

Sitecore Media Upload is not working for Safari or FF with Windows Authentication turned on

Recently, I have been spending time trying to figure out how to get Media Upload to work for Safari or FF when Windows Authentication is turned on IIS.

Safari or FF will ask for credential again when uploading files, even though you have entered the credential when you browse the website for the first time. When you enter the credential, Firefox will freeze while Safari will throw an error.

I have tried changing the config in Firefox by tweaking "network.automatic-ntlm-auth.trusted-uris". This setting can be shown by typing "about:config" in url bar. It still does not work.

I have then lodged a ticket with Sitecore support. Few days later they come back with a solution that is to enable "Anonymous" authentication in IIS for ‘/sitecore/shell/Applications/FlashUpload’ and ‘/sitecore/shell/Applications/Media’.

ASP:Repeater displaying different markup for the first item

There is a little trick i found here http://asp-net-whidbey.blogspot.com/2006/07/net-20-repeater-different-template-for.html that i think is really neat like to display different markup/html for the first item in the repeater.


<asp:placeholder runat="server" visible="<%# (Container.ItemIndex == 0) %>"%></asp:placeholder%>

Thursday, April 14, 2011

File Upload on Mac throwing an error

Today, I encountered an issue where uploading file on Mac is throwing "One or more files could not be uploaded. See the log for file for more details".

I investigated the issue, and it turns out to be enabling IIS "Windows Authentication" setting is the culprit. For some reason, file upload isnt working properly even though I have managed to Authenticate and login to Sitecore successfully.

Creating additional tab similar to "content" or "builder" tab

recently, I was asked to create additional tab similar to "content" or "builder" tab. Unfortunately there isnt much info on it. I managed to get the info needed to do this from my colleague, and here is field that govern the tabs.

Under Appearance Section (you will need to checked "standard fields" under view) look for "editor" or "editors" fields. Here you defined the controls that you want to display as the tab.


Wednesday, March 30, 2011

Enabling Expires Header on IIS7

Open up IIS Manager,

1. Locate the folder where files (e.g. js, css and images) are located and needed to be configured with Expires Headers.
2. Click on HTTP Response Headers
3. Under Action page, click Set Common Headers
4. By default, "Enable Http keep-alive" is checked. Leave this as it is.
5. Another tickbox "Expire Web content", ensure this is checked. You can set the expires as long as required.

Monday, March 28, 2011

GZIP

Today, i have been trying to get GZIP compression working for my local machine which runs IIS7 with Windows 7. For some reasons GZIP compression isnt working even though i have checked the applicationhost.config and mime type has been configured correctly.

Turn out the issues requires additional tweak.

Compression is 'locked' by default at the application level. As such, it needs to be 'unlocked'. this can be achieved via the command line or via the (extra download) iis7 admin tools.

eg. appcmd set config -section:urlCompression /doDynamicCompression:true

http://learn.iis.net/page.aspx/206/dynamic-compression/

Reference:

http://serverfault.com/questions/23788/need-help-with-some-iis7-web-config-compression-settings

Sunday, February 6, 2011

Parameter to sublayout (ASCX)

My colleague was having issue with Parameters that she assigned to Sublayout. For some reason the parameter that set in Presentation definition in Sitecore is returning empty when accessing it programmatically.

It turns out that Sitecore does not set the presentation properties by default. So we have to set this up before accessing it.