Pergunta

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

Foi útil?

Solução

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);
       }

Outras dicas

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;
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a sharepoint.stackexchange
scroll top