Hi, I have created a http module to update the list item but when i use the Update function of SPListItem object it gives the error: "Operation is not valid due to the current state of the object". Below is the HTTP Module i have written to update the List Item. Please suggest
namespace
SiteUsageModule
public class SiteUsage : IHttpModule
{
public void Init(HttpApplication httpApp)
static void OnBeginRequest(object sender, EventArgs a)
UsageLogger.LogSiteUsage(((HttpApplication)sender).Context.Request);
public void Dispose()
public static class UsageLogger
{
public static void LogSiteUsage(HttpRequest r)
try
{
const string rootSite = "http://localhost:4000/sites/testing";
const string listName = "PageUsageDetails";
SPWeb elevetedSite = null;
SPSecurity.RunWithElevatedPrivileges(delegate()
using (var site = new SPSite(rootSite))
using (SPWeb web = site.OpenWeb())
true;
SPList pageUsageDetails = elevetedSite.Lists[listName];
SPField pageUrl = pageUsageDetails.Fields["PageUrl"];
SPQuery colQuery = new SPQuery();
////string query = "No" + splitUrl[0] + "" + searchText + "" + searchText + "";
string query = "http://eagng4240:4000/sites/Testing/CMSStagingLibrary/Sites/antivirus.iyogi.net/webURL check1/webURL check1.aspx";
////Get values returned from the query.
SPListItemCollection itemCollection = pageUsageDetails.GetItems(colQuery);
////Check if there exist any unique value of the column.
if (itemCollection.Count == 1)
SPListItem item = itemCollection[0];
item.Web.AllowUnsafeUpdates =
true;
item[
"PageHitCount"] = Convert.ToInt32(item["PageHitCount"].ToString()) + 1;
//HttpContext.Current.Response.Write(item["PageHitCount"].ToString() + item["PageUrl"].ToString());
//item.SystemUpdate();
//item.Update();
item.Web.AllowUnsafeUpdates =
false;
elevetedSite.AllowUnsafeUpdates =
false;
//site.AllowUnsafeUpdates = false;
//web.Update();
}
}
catch(Exception ex)
//HttpContext.Current.Response.Write(ex.Message);
}
}
private static string GetHostAddress(IPAddress[] addresses)
foreach (IPAddress ip in addresses)
if (ip.ToString().Length <= 15)
return ip.ToString();
return "";
}
}
}
}
}
{
{
{
{
{
colQuery.Query = query;
{
elevetedSite = web;
}
}
});
elevetedSite.AllowUnsafeUpdates =
{
{
{
{ }
}
}
{
{
httpApp.BeginRequest += OnBeginRequest;
}
{