Friday, June 27, 2014

IIS ARR Reverse Proxy and HTTP Status Code 304

In IIS 7.5, reverse proxy using ARR v2, does not send 304 status code for subsequent requests which are cached on file system. Because of this, even if the actual website allows caching of requests in browser (client side), ARR always sends HTTP 200 code. This forces the browser to download the cached request again from server.

For some strange reason, ARR always send status code 200 if requests contains ETags.
So, basically if you want ARR to send 304 status code then ETags must be removed.

In IIS, Etags can be removed from response with the help IIS URL Rewrite module. Following outbound rule must be created to remove ETags:

<outboundrules>
  <rule name="Remove ETag">
    <match pattern=".+" servervariable="RESPONSE_ETag">
    <action type="Rewrite" value="">
  </action></match></rule>
</outboundrules>

For more details check below links:
http://stackoverflow.com/questions/24381694/iis-7-5-and-arr-304-status-code-not-sent-for-images
http://forums.iis.net/t/1213330.aspx?ARR+Disk+cache+return+200+instead+of+304+for+cached+files

Wednesday, June 25, 2014

Reading Complex Field Values in Sitecore WFFM

Sitecore Web Forms for Marketers is a Sitecore CMS module used for creating forms in a website. It has various set of fields like simple, list, complex, pre-filled etc.

Usually to access field value in code, Value property of AdaptedControlResult class is used.
For any list or complex types of fields, the Value property normally contains extra information.

For e.g., A WFFM form has a check-box list and the values for its items are 1,2,3,4,5. User selects 1,2,3 and submits the form.
Then in the server-side code the value of this field is:

<item>1</item><item>2</item><item>3</item>

To get a simple value with out item tags then GetSitecoreStyleValue method of FieldReflectionUtil class can be used.
Example code snippet:

AdaptedResultList fields;

// Get the form field by specifying the field name
AdaptedControlResult formField = fields.GetEntryByName("fieldName"); 

// complex value with item tags
string fieldValue = formField.Value;

// simple value without item tags
fieldValue = Sitecore.Form.Core.Utility.FieldReflectionUtil.GetSitecoreStyleValue(formField.FieldID, fieldValue);


BottomLine: Use FieldReflectionUtil class to get simplified version of form field values.

Tuesday, June 24, 2014

Extension Randomly Added in Sitecore Media Item URLs

In Sitecore 6.6, MediaManager randomly adds extension while generating URL for any Sitecore Media Item. This is a bug in Sitecore. A workaround is available to fix this issue.
MediaUrlOptions mediaUrlOpts = new MediaUrlOptions();
mediaUrlOpts.IncludeExtension = false;
Response.Write(MediaManager.GetMediaUrl(item, mediaUrlOpts));

In case extension is always needed in the URL then set IncludeExtension property to true.