Wednesday, 6 November 2013

Object of type 'System.Int32' cannot be converted to type Object of type 'System.Int32' cannot be converted to type 'System.Web.Security.Cryptography.Purpose

<!--  REMEMBER LAST LOGGED IN USER NAME 
            Specifies whether Sitecore will remember the last logged in user name on the login page (stored encrypted in a cookie). 
            If you set this to false, the user name field on the login page and change password page will always be blank.
            Default: true
      -->
 <setting name="Login.RememberLastLoggedInUserName" value="false"/>


Sitecore and .net 4.5 Bug Fixed

Maximum request length exceeded – No File Upload

If you are not using view state do – Enableviewstate = “false”.

If you need to store view state. Check why the data is so huge on view state. My case had a spam email with so much of data in it. 

Sitecore Rich text editor - stripping Iframe and Web contols.

Turn off HtmlEditor.SupportWebControls setting in web.config:


<setting name="HtmlEditor.SupportWebControls" value="false"/>

Monday, 28 January 2013

storing values in cache memory(Not sessions not applications)


public static class CacheUtils
    {
        private static readonly Cache cache = HttpRuntime.Cache;
        
        /// <summary>
        /// Gets data from cache      
        public static Object GetFromCache(string key)
        {
            return cache[key];
        }      
 
        public static void InsertIntoCache(string key, int cacheTimeInMinutes, Object obj)
        {
            cache.Insert(key, obj, null, DateTime.Now.AddMinutes(cacheTimeInMinutes),
                          Cache.NoSlidingExpiration, CacheItemPriority.Normal, OnRemove);
        }
 
        public static void OnRemove(string key, object cacheItem, CacheItemRemovedReason reason)
        {
            //log.Info("Object removed from cache: Key-" + key + ": Reason-" + reason);
        }
 
        public static void RemoveFromCache(string key)
        {
            cache.Remove(key);
        }
 
    }

Sunday, 27 January 2013

Reverse a string and sentence Linq Query


A string Reverse
string yString = "String to reverse";                
string rString = yString.Reverse().ToString(); 
Sentence reverse with each word in it...
string rString = string.Join(" ",from s in yString.Split(' ')
                                  select new String(s.Reverse().ToArray()));

Monday, 14 January 2013

Reg Expressions validator imp list


 Email : "^([0-9a-zA-Z]([-\.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$"



Only Numbers With Decimal :  "^[0-9]*\.?[0-9]+$"

Alphanumeric only :   "^[a-zA-Z0-9]*$"

Numbers with length between 2 to 5 Ex : "^([0-9]{2,5})$"

Numbers with Exact lenght(Example 5) : "^(\d{5})$"

Friday, 2 November 2012

File Upload Max Lenght exeeded Error


The default setting for thr file upload control is 4MB we can overwrite in web.config.
If you are using IIS7 use both else  maxRequestLength is enough.

In system.web
<httpRuntime maxRequestLength="1048576" executionTimeout="3600" />

And in system.webServer
<security>
    <requestFiltering>
        <requestLimits maxAllowedContentLength="1073741824" />
    </requestFiltering>
</security>
IMPORTANT: Both of these values must match. In this case, my max upload is 1024 megabytes.
maxRequestLength has 1048576 KILOBYTES, and maxAllowedContentLength has 1073741824 BYTES.
I know it's obvious, but it's easy to overlook.