“当前不允许更新在获取请求上”错误创建站点集合
-
16-10-2019 - |
题
我正在使用Windows Server 2008 Enterprise使用SharePoint Server 2007 Enterprise。我部署了一个出版门户。我正在使用VSTS 2008 + C# + .NET 3.5 + ASP.NET + SharePoint Server 2007 SDK开发ASP.NET Web应用程序。
这是我的代码片段,我有错误 - “当前不允许在获取请求上更新”。有什么想法如何解决?
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", "owneremail@foo.com");
}
catch (Exception ex)
{
Response.Write(ex.ToString() + "\t" + ex.StackTrace);
}
}
更新1: 我在以下代码中遇到了相同的错误,
SPContext.Current.Web.AllowUnsafeUpdates = true;
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", "owneremail@foo.com");
解决方案
请注意,Spsite还具有您可以尝试的允许使用属性。
如果您更改此操作,请在尝试/最后进行操作,以确保您的网站可以使您的网站无法访问交叉脚本攻击(从您的代码示例中看来,您已经绕过了从所有子手段中绕过XSS保护网站,因此您可能需要再次启用!)。
最终,AllowUnSafeupdates属性将重置为其默认值(任何调用spweb.invalidate()等的操作),但在此之前,您的站点将容易受到XSS攻击。
其他提示
我认为你需要设置 AllowUnsafeUpdates
在调用此代码的网络上。
bool currentSetting = SPContext.Current.Web.AllowUnsafeUpdates;
SPContext.Current.Web.AllowUnsafeUpdates = true;
... do your work here
SPContext.Current.Web.AllowUnsafeUpdates = currentSetting;
如果您真的想通过邀请进行此操作,则可以执行“ sputility.valiatesformdigest()”也应该做到这一点,而无需触摸allowunsafeupdates属性(我认为,这确实应该避免使用)