我正在将SharePoint Server 2007 Enterprise与Windows Server 2008 Enterprise配合使用。我部署了一个发布门户。我正在开发使用VSTS 2008 + C#+ .Net 3.5 + ASP.Net + SharePoint Server 2007 SDK的ASP.Net Web应用程序。遇到错误 - “GET请求当前不允许更新”
这里是我的代码片断,我得到错误 - “GET请求目前不允许更新”。任何想法如何解决?
Microsoft.SharePoint.SPException: Updates are currently disallowed on GET requests. To allow updates on a GET, set the 'AllowUnsafeUpdates' property on SPWeb.
protected void Page_Load(object sender, EventArgs e)
{
try
{
SPWebApplication webApp = SPContext.Current.Site.WebApplication;
SPSiteCollection siteCollections = webApp.Sites;
foreach (SPSite item in siteCollections)
{
SPWeb webItem = item.OpenWeb();
webItem.AllowUnsafeUpdates = true;
}
SPSite newSiteCollection = siteCollections.Add("sites/myblog",
"New Sample Site", "New Sample Site Description", 1033, "BLOG#0",
"foo\\foouser", "Owner name", "[email protected]");
}
catch (Exception ex)
{
Response.Write(ex.ToString() + "\t" + ex.StackTrace);
}
}
你的意思是,如果我把你的代码放入aspx的Page_Load中的try/catch块中? – George2 2010-02-24 13:39:13
是的,您可以将此代码包装在您调用SPSiteCollection对象的.Add方法的位置。 并且不要循环SPWeb对象将AllowUnsafeUpdates设置为true(并且您甚至不会调用SPWeb.Dispose)。看到这里:http://msdn.microsoft.com/en-us/library/aa973248.aspx SPSite iteself有AllowUnsafeUpdates属性 - 你应该使用它。 – 2010-02-24 14:28:22
谢谢,问题回答! – George2 2010-02-25 05:07:07