Surendra Sharma

Surendra Sharma

Search This Blog

Showing posts with label Tech Tips. Show all posts
Showing posts with label Tech Tips. Show all posts

Thursday, March 23, 2017

How to expire Sitecore session forcefully



In one of our project, I have to forcefully expire the Sitecore session so that it flush the data to MongoDB.

For this either you can restart IIS or start-stop your website. But this action require you to login into the system. But what if you are accessing Sitecore remotely or over the internet.

So I write this script which expire the session and clear the Sitecore analytics related cookies.

<%@ Page Language="C#" AutoEventWireup="true" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <%
            Context.Session.Abandon();
            HttpContext.Current.Request.Cookies.Remove("ASP.NET_SessionId");
            Response.Cookies.Add(new HttpCookie("ASP.NET_SessionId", string.Empty));
            HttpContext.Current.Request.Cookies.Remove("SC_ANALYTICS_SESSION_COOKIE");
            Response.Cookies.Add(new HttpCookie("SC_ANALYTICS_SESSION_COOKIE", string.Empty));
            HttpContext.Current.Request.Cookies.Remove("SC_ANALYTICS_GLOBAL_COOKIE");
            Response.Cookies.Add(new HttpCookie("SC_ANALYTICS_GLOBAL_COOKIE", string.Empty));
        %>
    </form>
</body>
</html>

I called this script as "ForceSessionEnd.aspx" and keep it in "Website" folder.

Access this script over the browser as "http://yourinstancename/forcesessionend.aspx".

After running this page, you will get latest data on mongo database.

Feel free to add more cookies as per your need.

I hope you like this Sitecore script. Stay tuned for more Sitecore related articles.

Till that happy Sitecoring :)
 
Please leave your comments or share this script if it’s useful for you.

Wednesday, March 22, 2017

Failed to perform MaxMind lookup

In our CD server we are recelving lots of log errors related with MaxMind lookups as
 
ManagedPoolThread #17 00:37:24 ERROR Failed to perform MaxMind lookup
ManagedPoolThread #17 00:37:24 ERROR Failed to perform GeoIp lookup for 192.168.0.74
Exception: Sitecore.Analytics.Lookups.CannotParseResponseException
Message: Unexpected format. Cannot parse the MaxMind response for IP address: 192.168.0.74
Source: Sitecore.Analytics
   at Sitecore.Analytics.Lookups.MaxMindProvider.GetInformationByIp(String ip)
   at Sitecore.Analytics.Lookups.GeoIpManager.GetDataFromLookupProvider(GeoIpHandle geoIpHandle)

We want to stop this MaxMind lookup functionality as we are not using this in our project.

Solution:

We can disable MaxMind lookup operation by editing “Sitecore.Analytics.config” file and by making “false” entry to “Analytics.PerformLookup” key as

<!--  ANALYTICS PERFORM LOOKUP
      Determines if this server performs the lookups (DNS and URLs). Only one server should be responsible for performning the lookup.
      Default: true
-->
<setting name="Analytics.PerformLookup" value="false" />

After this change we didn’t find any MaxMind related errors in Sitecore log file.

I hope you like this Sitecore tip. Stay tuned for more Sitecore related articles.

Till that happy Sitecoring :)
 
Please leave your comments or share this tip if it’s useful for you.

Tuesday, March 21, 2017

Solved : Unable to select or create items under a particular node in Sitecore



This is real life scenario where, clicking one particular node on the Sitecore content tree is throwing the error in in one of our project on Sitecore Authoring environment (CM).
 
This error is occurring only in master database. But when we switch to web database and select the same node, it works fine over there. We had also implemented custom pipelines for creating custom links, some item save events, url resolvers, etc. 

We tried to overwrite the Sitecore package for the same node from different Server environment. But even overwrite function also failed.

Below are the logs which are generating while expanding the node in Sitecore content tree:

6624 08:15:10 ERROR Failed to sort items
Exception: System.ArgumentNullException
Message: Value cannot be null.
Parameter name: uri
Source: Sitecore.Kernel
   at Sitecore.Data.ItemUri..ctor(ItemUri uri)
   at Sitecore.Data.ItemUri..ctor(String itemUri)
   at Sitecore.Data.Items.Item.GetItemUriFromSourceItem()
   at Sitecore.Data.Items.Item.get_SourceUri()
   at Sitecore.Data.Fields.Field.GetSourceItem()
   at Sitecore.Data.Fields.Field.GetInheritedValue(Boolean allowStandardValue)
   at Sitecore.Data.Fields.Field.GetValue(Boolean allowStandardValue, Boolean allowDefaultValue)
   at Sitecore.Data.Items.ItemAppearance.get_Sortorder()
   at Sitecore.Data.Comparers.ItemComparer.ExtractKey(Item item)
   at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Sitecore.Data.Managers.ItemProvider.Sort(ItemList items, Item owner)

6624 08:15:10 ERROR Error in gutter renderer
Exception: System.ArgumentNullException
Message: Value cannot be null.
Parameter name: uri
Source: Sitecore.Kernel
   at Sitecore.Data.ItemUri..ctor(ItemUri uri)
   at Sitecore.Data.ItemUri..ctor(String itemUri)
   at Sitecore.Data.Items.Item.GetItemUriFromSourceItem()
   at Sitecore.Data.Items.Item.get_SourceUri()
   at Sitecore.Data.Fields.Field.GetSourceItem()
   at Sitecore.Data.Fields.Field.GetInheritedValue(Boolean allowStandardValue)
   at Sitecore.Data.Fields.Field.GetValue(Boolean allowStandardValue, Boolean allowDefaultValue)
   at Sitecore.Data.Fields.Field.get_Value()
   at Sitecore.Shell.Applications.ContentEditor.Gutters.WorkflowState.GetIconDescriptor(Item item)
   at Sitecore.Shell.Applications.ContentEditor.Gutters.GutterRenderer.Render(HtmlTextWriter output, Item item)

6624 08:15:10 ERROR Application error.
Exception: System.Web.HttpUnhandledException
Message: Exception of type 'System.Web.HttpUnhandledException' was thrown.
Source: System.Web
   at System.Web.UI.Page.HandleError(Exception e)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.ProcessRequest()
   at System.Web.UI.Page.ProcessRequest(HttpContext context)
   at ASP.sitecore_shell_applications_content_manager_execute_aspx.ProcessRequest(HttpContext context) in c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\943e1849\478cf6da\App_Web_jv4g5f10.3.cs:line 0
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
Nested Exception
Exception: System.ArgumentNullException
Message: Value cannot be null.
Parameter name: uri
Source: Sitecore.Kernel
   at Sitecore.Data.ItemUri..ctor(ItemUri uri)
   at Sitecore.Data.ItemUri..ctor(String itemUri)
   at Sitecore.Data.Items.Item.GetItemUriFromSourceItem()
   at Sitecore.Data.Items.Item.get_SourceUri()
   at Sitecore.Data.Fields.Field.GetSourceItem()
   at Sitecore.Data.Fields.Field.GetInheritedValue(Boolean allowStandardValue)
   at Sitecore.Data.Fields.Field.GetValue(Boolean allowStandardValue, Boolean allowDefaultValue)
   at Sitecore.Data.Fields.Field.get_Value()
   at Sitecore.Shell.Applications.ContentManager.Sidebars.Tree.GetClassName(Item item, Boolean active)
   at Sitecore.Shell.Applications.ContentManager.Sidebars.Tree.RenderTreeNode(HtmlTextWriter output, Item item, String inner, Boolean active)
   at Sitecore.Shell.Applications.ContentManager.Sidebars.Tree.RenderChildNodes(ID parent)
   at Sitecore.Shell.Applications.ContentManager.ExecutePage.Page_Load(Object sender, EventArgs e)
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

We tried different approaches but for couple of days we were unable to resolve the issue. But finally we resolve it.

Solution:

The solution is pretty simple.

We simply deleted that node from master database and transferred the node from Web database to Master database. That resolved the issue.

Now we are able to select the node and able to create child items under the node.
Sometimes simple tricks also works :)

I hope you like this Sitecore tip. Stay tuned for more Sitecore related articles.

Till that happy sitecoring :)
 
Please leave your comments or share this tip if it’s useful for you.