Wednesday, 6 November 2013

Sitecore - sublayout GetParametervalue

private string GetParameterValue(string key)
        {
            Sublayout sublayout = uc != null ? (uc.Parent as Sublayout) : (this.Parent as Sublayout);
            if(sublayout != null)
            {
                if(!String.IsNullOrEmpty(sublayout.Parameters))
                {
                    Database db = Sitecore.Context.Database;

                    NameValueCollection parameters = Sitecore.Web.WebUtil.ParseUrlParameters(sublayout.Parameters);

                    if(parameters != null && parameters[key] != null)
                    {
                        return parameters[key].ToString();
                    }
                }
            }

            return String.Empty;

        }

Sitecore DMS Poll Module

·         After Installation od Sitecore DMS, we can able to install DMS Poll Module on it.
·         Software can be downloaded from here - http://marketplace.sitecore.net/en/Modules/Poll_Module.aspx
·         The document is for old OMS Poll Installation but it will be understandable for the new DMS as well apart from two points metioned below:
o    DMS Poll Voting Sublayout​ - Editor options (which are wrong by default. Change it to below paths)
§  Datasource Location - /sitecore/content/Home/LeagueAgainstCruelSports/Site Collection/Polls​
§  DataSource Template - /sitecore/templates/Sitecore Modules/DMS Poll module/DMS Poll

o    While adding poll control to the page presentation details add the created poll in the Datasource not as a parameter.

Sitecore RSS Feed Custom Functionality

Sometimes it is difficult to write complex xPath and sitecore Queries, to make RSS Feed work like our requirements. So, it is better to Override the Sitecore class called Sitecore.Syndication.PublicFeed.
 
Example
 
public class CustomFeed : Sitecore.Syndication.PublicFeed
    {
        public List<Item> EmbargoPressReleases = new List<Item>();

        public override IEnumerable<Sitecore.Data.Items.Item> GetSourceItems()
        {
            var Items = base.GetSourceItems();

            foreach(Item i in Items)
            {
                if(i.TemplateID == Consts.Template.PressRelease)
                {
                    if(Sitecore.DateUtil.IsoDateToDateTime(i.Fields[Consts.FieldName.PublishDate].ToString()) <= DateTime.Now)
                    {
                        EmbargoPressReleases.Add(i);
                    }
                }
            }
            return EmbargoPressReleases;
        }

    }

Sitecore FastQuery Returing Items in wrong Order.

Remove Fast from your query. Or sort it with the field name __sortOrder

Sitecore SubItems Sort Order.

Use the Home Ribbion Sorting Tab.

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.

Wednesday, 3 October 2012

Create fake certificate in IIS 6

Every time I need to enable https / ssl for a development or staging server I spend 30 minutes googling for instructions. Now I'm blogging just to remind myself how it's done:

Install the IIS 6 Resource Kit referenced at:
http://support.microsoft.com/kb/840671 from:
http://www.microsoft.com/downloads/details.aspx?FamilyID=56fc92ee-a71a-4c73-b628-ade629c89499

Obtain the site Id of the website you want to install the certificate for by clicking on the Web Sites major heading in the left hand side of the IIS admin tool and view the "Identifier" on the right hand side for whichever site you need. This is the site ID. further instructions at: http://weblogs.asp.net/owscott/archive/2005/07/29/421058.aspx

Run the following command replacing www.example.com with the host header of your site and 123456 with the site id obtained in the previous step (the /V:365 indicates that the certificate should be valid for 365 days, adjust accordingly):
"C:\Program Files\IIS Resources\SelfSSL\selfssl.exe" /T
/N:CN=www.example.com /V:365 /S:123456

Wednesday, 19 September 2012

SOAP Background

 
Such a nice article on Soap have a try very interesting......
 
 

Monday, 17 September 2012

Tuesday, 4 September 2012

IIS's Overlapping App Pools





Good one.........



Category does not exist' error when viewing IIS Worker Processes in IIS Manager


I ran into an interesting problem recently when using the new Worker Processes feature in the Internet Information Services (IIS) Manager for IIS 7.0. The Worker Processes feature is a great addition to IIS, and it's used to view practical information about the worker processes that are currently in use on your system; for example: the names of application pools that are associated with worker processes, worker process PIDs, CPU and byte usage statistics, etc.
So it's understandable that I was a little taken aback when I double-clicked the feature recently and I was greeted with an error dialog that stated "There was an error while performing this operation. Details: Category does not exist."
The last time that I saw that error dialog was a couple of years ago during the early days of the Windows Server 2008 beta when some of the IIS features had not been fully-written, so I emailed Carlos Aguilar Mares like I always do when I have a question about why I think something in the UI isn't behaving as expected. Carlos asked me to take a look at the performance counters on my server, and it was missing the "Process" counters. Armed with this knowledge, Carlos put me in touch with Matt E. and Wedson F. here at Microsoft, and the two of them worked with me to troubleshoot what was going on.
First of all, Matt had me take a look in the Windows Application log for any events with "Perflib" as the source, and I found the following two events:

Event #1

Log Name:
Application
Source:
Microsoft-Windows-Perflib
Date:
9/28/2008 5:19:26 PM
Event ID:
1010
Task Category:
None
Level:
Error
Keywords:
Classic
User:
N/A
Computer:
webserver.domain.local
Description:
The Collect Procedure for the "PerfProc" service in DLL "C:\Windows\system32\perfproc.dll" generated an exception or returned an invalid status. The performance data returned by the counter DLL will not be returned in the Perf Data Block. The first four bytes (DWORD) of the Data section contains the exception code or status code.
Binary Data:
050000C0

Event #2

Log Name:
Application
Source:
Microsoft-Windows-Perflib
Date:
9/28/2008 5:19:27 PM
Event ID:
1017
Task Category:
None
Level:
Error
Keywords:
Classic
User:
N/A
Computer:
webserver.domain.local
Description:
Disabled performance counter data collection from the "PerfProc" service because the performance counter library for that service has generated one or more errors. The errors that forced this action have been written to the application event log. Correct the errors before enabling the performance counters for this service.
The binary data ("050000C0") for the first error was obviously the HRESULT for an access violation in little-endian format (e.g. "0xC0000005"), and the second error explained why my counters were missing - something went wrong at some point and Windows disabled the process performance counters. Wedson had me run the following command:
lodctr /q:PerfProc
Which returned the following output:
Performance Counter ID Queries [PERFLIB]:
    Base Index: 0x00000737 (1847)
    Last Counter Text ID: 0x00001E86 (7814)
    Last Help Text ID: 0x00001E87 (7815)

[PerfProc] Performance Counters (Disabled)
    DLL Name: perfproc.dll
    Open Procedure: OpenSysProcessObject
    Collect Procedure: CollectSysProcessObjectData
    Close Procedure: CloseSysProcessObject
This showed that the PerfProc performance counters were disabled, and to remedy the problem I just needed to run the following command:
lodctr /e:PerfProc
After running this command, my process performance counters showed up in the Windows Performance Monitor and the IIS Worker Processes feature started working again.

Parting Thoughts and Such

Matt sent me a recap email later explaining that the crux of the problem was that the provider for the "Process" performance counter had been disabled on my server because that performance counter's collect procedure had caused an access violation ("0xC0000005") at some point in the past; this is usually due to some other performance counter misbehaving and corrupting the memory heap. In a general situation, checking the event viewer for errors with "Perflib" as the source will let you know if something has caused an error, and you can use "lodctr /q:<provider name>" to query the status of a provider or "lodctr /e:<provider name>" to enable a provider. In this particular situation, after the "PerfProc" provider was re-enabled the Worker Processes feature in IIS Manager resumed working.

Saturday, 1 September 2012

JavaScript for post backs

I really don't know why people still use JavaScript in the websites. As browsers are updated day by day they are not compatible with all the browsers.

I found a serious problem in one of our websites yesterday, because of the Mozilla Firefox updated their browser.

Need to figure this out.


ASP.NET 4.5

Check this link for the new asp.net 4.5 features and visual studio 2012.

http://www.asp.net/web-forms/tutorials/aspnet-45/getting-started-with-aspnet-45-web-forms/introduction-and-overview

Hope you guys like it.