Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I wrote a ASP.NET Handler module for sharepoint 2010 web application. it is running .But I added this code, occured error Code:

string tema = "/_catalogs/theme/Classic.thmx";
ThmxTheme tm = ThmxTheme.Open(SPContext.Current.Site, tema);
ThmxTheme.SetThemeUrlForWeb(SPContext.Current.Web, tm.ServerRelativeUrl);

Error:

<nativehr>0x80004005</nativehr><nativestack></nativestack>Updates are currently disallowed on GET requests.  To allow updates on a GET, set the 'AllowUnsafeUpdates' property on SPWeb. 

what is my error. Thanks

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

Not a good idea to use a handler for this. This code would run every time a page is called. Instead use the WebProvisioned event to set the theme when a site is created.

@toni-frankola has an example on how to do this here.

public override void WebProvisioned(SPWebEventProperties properties)
       {
           ThmxTheme theme = ThmxTheme.Open(properties.Web.Site, ThmxTheme.GetThemeUrlForWeb(properties.Web.ParentWeb));
           theme.ApplyTo(properties.Web, false);
           properties.Web.Update();
           base.WebProvisioned(properties);
       }
share|improve this answer
    
Thanks Anders.. This example is good for me. ASP.NET Handler module is not correct for this job. I prepared event receiver for web WebProvisioned eventhandler. it is working now. Thx. –  Yasin Nov 27 '11 at 11:06
add comment

When you tries to save data to DB on GET request, SharePoint trims this operation by security reason. To solve this problem you can use AllowUnsafeUpdates property of SPWeb.

bool unsafeUpdates = SPContext.Current.Web.AllowUnsafeUpdates;
try
{
    SPContext.Current.Web.AllowUnsafeUpdates = true;
    // your code
}
finally
{
    SPContext.Current.Web.AllowUnsafeUpdates = unsafeUpdates;
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.