Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Sharepoint中的web.AllowUnsafeUpdates默认值是否始终为false?_C#_Sharepoint_Sharepoint 2010_Object Model_Sharepoint Object Model - Fatal编程技术网

C# Sharepoint中的web.AllowUnsafeUpdates默认值是否始终为false?

C# Sharepoint中的web.AllowUnsafeUpdates默认值是否始终为false?,c#,sharepoint,sharepoint-2010,object-model,sharepoint-object-model,C#,Sharepoint,Sharepoint 2010,Object Model,Sharepoint Object Model,这是我的示例代码: SPWeb web = SPContext.Current.Web SPList list = web.Lists["TestList"]; try { web.AllowUnsafeUpdates = true; list.Title = "Test"; list.Update(); } finally { web.AllowUnsafeUpdates = false; } 我最后删除了代码块,然后再试一次。我发现web.AllowUn

这是我的示例代码:

SPWeb web = SPContext.Current.Web
SPList list = web.Lists["TestList"];

try {
    web.AllowUnsafeUpdates = true;
    list.Title = "Test";
    list.Update();
}

finally {
    web.AllowUnsafeUpdates = false;
}
我最后删除了代码块,然后再试一次。我发现web.AllowUnsafeUpdates仍然是假的。 这是否意味着不需要设置web.AllowUnsafeUpdates=false?

web.AllowUnsafeUpdates是为SPContext.Current.web请求的持续时间设置的,如果通过GetWeb从SPSite获得,则为相应SPWeb对象的生存期设置的。。。或网络[]

根据重试的内容,您可能会收到新请求的SPWeb的新副本

与try/finally一样,将AllowUnsafeUpdates保持为范围很广的代码段的tru是一种很好的做法。可能有其他代码会在同一请求期间运行,并且错误地能够在不允许的情况下更新对象。

web.AllowUnsafeUpdates是为SPContext.Current.web请求的持续时间设置的,或者如果通过GetWeb从SPSite获得,则为相应SPWeb对象的生存期设置的。。。或网络[]

根据重试的内容,您可能会收到新请求的SPWeb的新副本

与try/finally一样,将AllowUnsafeUpdates保持为范围很广的代码段的tru是一种很好的做法。在同一请求期间可能会有其他代码运行,并且在不允许的情况下错误地能够更新对象