We are getting the below error in our application logs. But the error occurs sometimes only.
SmartTargetClaimStore:SmartTargetModule-context_PreRequestHandlerExecute(): Object reference not set to an instance of an object.
Please suggest where to look for the issue, as SmartTarget is a black box for us. TIA.
Update: Code that throws the above error. Please let me know if we need to add an additional check to handle the same.
#region HttpModule
/// <summary>
/// SmartTarget Module
/// </summary>
public class SmartTargetModule : IHttpModule
{
/// <summary>
/// Module Intialization
/// </summary>
/// <param name="context">Application Context which will be passed to this function by IIS Pipeline</param>
public void Init(HttpApplication context)
{
context.PreRequestHandlerExecute += context_PreRequestHandlerExecute;
}
private void context_PreRequestHandlerExecute(object sender, EventArgs e)
{
try
{
HttpRequest request = HttpContext.Current.Request;
if (request.Path != null && (request.ServerVariables["SCRIPT_NAME"].Contains(".aspx")))
{
NameValueCollection nvc = request.QueryString;
string[] keys = nvc.AllKeys;
//Reading all QueryString parameter adding them to AmbientClaimStore
foreach (string key in keys)
{
string value = nvc[key].ToString();
value = HttpUtility.UrlDecode(value);
value = value.Contains(":") ? value.Substring(0, value.IndexOf(":")) : value;
ClaimStoreManager.AddPredefinedClaimToStore(key.Trim().ToLower(), value.Trim().ToLower());
}
}
}
catch (Exception ex)
{
Log.Message(string.Format("SmartTargetClaimStore:SmartTargetModule-context_PreRequestHandlerExecute(): {0} ", ex.Message), System.Diagnostics.TraceEventType.Error);
Log.Exception(ex);
}
}........