SharePoint 2010 - System.UnauthorizedAccessException: Access is denied
来源:互联网 发布:局域网 文件复制软件 编辑:程序博客网 时间:2024/05/16 06:56
I am sure many would have experienced this issue while connecting to a SharePoint site from an Asp.Net application. You normally would get these errors:
1. System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) at Microsoft.SharePoint.Utilities.SPUtility.HandleAccessDenied(Exception ex) at Microsoft.SharePoint.Library.SPRequest.GetListsWithCallback(String bstrUrl, Guid foreignWebId, String bstrListInternalName, Int32 dwBaseType, Int32 dwBaseTypeAlt, Int32 dwServerTemplate, UInt32 dwGetListFlags, UInt32 dwListFilterFlags, Boolean bPrefetchMetaData, Boolean bSecurityTrimmed, Boolean bGetSecurityData, Boolean bPrefetchRelatedFields, ISP2DSafeArrayWriter p2DWriter, Int32& plRecycleBinCount) at Microsoft.SharePoint.SPListCollection.EnsureListsData(Guid webId, String strListName) at Microsoft.SharePoint.SPListCollection.GetListByName(String strListName, Boolean bThrowException) at _Default.btnClick_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\Contoso\Default.aspx.cs:line 35
2. The Web application at http://localhost/sites/SPApplication101/ could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application.
However, if you try to access the same SharePoint application from a console application or windows application (provided the target framework is Any CPU or x64; because, SharePoint 2010runs in x64 mode only).
Now, there could be following reasons behind these errors.
1. Your ASP.NET application may be targeting to x86 framework and not Any CPU or x64.
2. The user account which is running the ASP.NET application may not have access to SharePoint application.
3. The application pool identify of the application pool of the ASP.NET application doesn’t have the access to SharePoint.
The solution to the above:
1. Make sure your ASP.NET application is targeting x64/Any CPU.
2. Run your code inside the block “SPSecurity.RunWithElevatedPrivileges”.
3. Make sure the application identity of the app pool of ASP.NET application has the access to the SharePoint application which your accessing. Alternatively, you can use the SharePoint’s application with your ASP.NET application.
try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
SPSite mySite = new SPSite("http://localhost/sites/SPApplication101/");
using (SPWeb myWeb = mySite.OpenWeb())
{
int i = 1;
string strFolder = "Folder";
mySite.AllowUnsafeUpdates = true;
myWeb.AllowUnsafeUpdates = true;
SPDocumentLibrary docLibrary = (SPDocumentLibrary)myWeb.Lists["Word Docs"];
SPFolderCollection myFolders = myWeb.Folders;
if (docLibrary != null)
{
while (i <= 10)
{
strFolder = strFolder + " " + i.ToString();
if (!myWeb.GetFolder(strFolder).Exists)
{
myFolders.Add(docLibrary.ParentWebUrl + "/Word%20Docs/" + strFolder + "/");
docLibrary.Update();
}
strFolder = "Folder";
i++;
}
}
}
});
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
-------------
Hope this helps many!
- SharePoint 2010 - System.UnauthorizedAccessException: Access is denied
- unity exe运行时出现UnauthorizedAccessException: Access to the path“”is denied.
- SharePoint 2013 On Azure 解决 SCRIPT5: Access is denied. 问题
- Access is denied: 'AjaxPro'
- Access is denied
- Error---Access is denied
- 550 Access is denied.
- Cannot copy Access is Denied
- IPC Port 'Access is denied'
- FTP 550 Access is denied.
- mongodbexport出现Access is denied
- Unable to open the physical file "d:\***.mdf". Operating system error 5: "5(Access is denied.)".
- 异常详细信息: System.UnauthorizedAccessException:
- System.UnauthorizedAccessException: 拒绝访问。
- System.UnauthorizedAccessException: 拒绝访问
- 一个System.UnauthorizedAccessException错误
- mscorlib thrown System.UnauthorizedAccessException
- System.UnauthorizedAccessException: 拒绝访问
- NBU网络备份大全之oracle系统冷备份
- UBuntu11.10下编译android源码2.3.5
- linux驱动学习第二天(linux内核及其编程1)
- oracle过程与函数的基本语法
- poj 匈牙利二分匹配 模板 poj题目
- SharePoint 2010 - System.UnauthorizedAccessException: Access is denied
- 将linux用户加入sudo组中
- 用vector取代C-style的数组
- 常用排序算法总结
- PHP 5.3 和 Zend Debugger
- SQL * Plus - SET TIMING 命令
- android 模拟器延时(处理方法)
- Socket嵌套字同步异步通信的原理
- Hadoop Streaming —— grep