您的位置:首页 > 其它

"Microsoft.SharePoint.SPException: 此网页的安全性验证无效并且可能损坏"解决办法

2009-07-30 12:27 465 查看
今天在往MOSS列表里写数据时,总是报错。一开始我用的是普通用户的身份,只有查看权限的用户,我以为是没有权限向列表里面写数据,后来我把写数据的代表提升中权限后也不不可以。还是出现下面的错误:

“Microsoft.SharePoint.SPException: 此网页的安全性验证无效并且可能损坏。请单击 Web 浏览器中的“后退”,刷新网页,再重试操作。 ---> System.Runtime.InteropServices.COMException (0x8102006D): 此网页的安全性验证无效并且可能损坏。请单击 Web 浏览器中的“后退”,刷新网页,再重试操作。
在 Microsoft.SharePoint.Library.SPRequestInternalClass.AddOrUpdateItem(String bstrUrl, String bstrListName, Boolean bAdd, Boolean bSystemUpdate, Boolean bPreserveItemVersion, Boolean ...”

后来看了一下SDK:

在很多操作moss站点资源的地方需要设置一个属性AllowUnsafeUpdates 属性,并且设置为true,这样是允许不安全的更新操作。 我后来加了下这样的代码问题得到解决。

出错代码:

SPSite spSite = SPContext.Current.Site;
SPWeb spWeb = SPContext.Current.Web;
SPUser user = spWeb.CurrentUser;

string sName = user.Name;

SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite spSiteNew = new SPSite(spSite.ID))
{
using (SPWeb spWebNew = spSiteNew.OpenWeb(spWeb.ID))
{
SPList list = spWebNew.Lists["视频列表"];
SPListItem newItem = list.Items.Add();

string sMmsUrlAddress = ConfigurationManager.AppSettings["MmsUrlAddress"];
string sVideoDownlAddress = ConfigurationManager.AppSettings["VideoDownlAddress"];

newItem["标题"] = txtTitle.Text.Trim();
newItem["在线观看地址"] = sMmsUrlAddress + "/" + sVideoName;
newItem["HTTP地址"] = sVideoDownlAddress + "/" + sVideoName;
newItem["缩略图"] = sImageUrl;

newItem.Update();

Page.ClientScript.RegisterStartupScript(this.GetType(), "myscript", "alert('视频上传成功!');", true);

txtTitle.Text = "";
txtRemary.Text = "";
}
}
});

修改后的代码:

SPSite spSite = SPContext.Current.Site;
SPWeb spWeb = SPContext.Current.Web;
SPUser user = spWeb.CurrentUser;

string sName = user.Name;

SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite spSiteNew = new SPSite(spSite.ID))
{
using (SPWeb spWebNew = spSiteNew.OpenWeb(spWeb.ID))
{
SPList list = spWebNew.Lists["视频列表"];
SPListItem newItem = list.Items.Add();

string sMmsUrlAddress = ConfigurationManager.AppSettings["MmsUrlAddress"];
string sVideoDownlAddress = ConfigurationManager.AppSettings["VideoDownlAddress"];

newItem["标题"] = txtTitle.Text.Trim();
newItem["在线观看地址"] = sMmsUrlAddress + "/" + sVideoName;
newItem["HTTP地址"] = sVideoDownlAddress + "/" + sVideoName;
newItem["缩略图"] = sImageUrl;
spWebNew.AllowUnsafeUpdates = true;

newItem.Update();
spWebNew.AllowUnsafeUpdates = false;

Page.ClientScript.RegisterStartupScript(this.GetType(), "myscript", "alert('视频上传成功!');", true);

txtTitle.Text = "";
txtRemary.Text = "";
}
}
});

以普通用户的身份向MOSS站点时面写数据或更新数据时都需允许不安全的更新操作

AllowUnsafeUpdates = true;

,这样才可以操作成功。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐