【问题标题】:Authenticate user for Sharepoint Online using VB.NET使用 VB.NET 对 Sharepoint Online 用户进行身份验证
【发布时间】:2017-03-28 01:54:09
【问题描述】:

我对将 Sharepoint Online 与 vb.net 程序链接完全不熟悉,任何建议肯定会有所帮助。

我添加了 2 个 .dll 文件的参考,Microsoft.Sharepoint.Client 和 Microsoft.Sharepoint.Client.Runtime。它们是从链接SharePoint Server 2013 Client Components SDK 下载的。

下面是我的代码,

 Imports Microsoft.SharePoint.Client
 Imports Microsoft.SharePoint
 Imports Microsoft
 Imports System.Net
 Imports System.Security

Public Class FilesRetrievalFromSharePoint
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


    Using ClientContext As New ClientContext("https://sample.sharepoint.com/Home.aspx")

        Dim password As New System.Security.SecureString()

        For Each c As Char In "pw@12345".ToCharArray()
            password.AppendChar(c)
        Next


        ClientContext.Credentials = New SharePointOnlineCredentials("user1@sample.com", password)
        Dim web As Web = ClientContext.Web

        ClientContext.Load(web)
        ClientContext.ExecuteQuery()

    End Using
End Sub

以及下面的其他几个类End Sub

Private Class SharePointOnlineCredentials
    Implements ICredentials

    Private password As SecureString
    Private v As String

    Public Sub New(v As String, password As SecureString)
        Me.v = v
        Me.password = password
    End Sub

    Public Function GetCredential(uri As Uri, authType As String) As NetworkCredential Implements ICredentials.GetCredential
        Throw New NotImplementedException()
    End Function
End Class

我将在ExecuteQuery() 遇到的错误是

Microsoft.SharePoint.Client.dll 中出现“System.Net.WebException”类型的异常,但未在用户代码中处理

附加信息:远程服务器返回错误:(403) Forbidden。

我了解这是由于身份验证问题,并且 Sharepoint 网址是为公司中的授权用户设计的。假设代码中的凭据属于授权用户。

是由于编码错误还是由于公司 IT 安全政策?

【问题讨论】:

    标签: vb.net authentication sharepoint


    【解决方案1】:

    换行 使用 ClientContext 作为新的 ClientContext("https://sample.sharepoint.com/Home.aspx")

    到 使用 ClientContext 作为新的 ClientContext("https://sample.sharepoint.com") 如果您打算使用其他网站 采用 使用 ClientContext 作为新的 ClientContext("https://sample.sharepoint.com/sites/yoursite")

    不要使用页面连接到网站。

    【讨论】:

    • 嗨@Guruparan,谢谢您的回复。不,它仍然给我 403 错误。
    • @TanStanley 您是否正确替换了网站网址? sample.sharepoint.com
    • 出于测试目的,我使用了 Using ClientContext As New ClientContext("sample.sharepoint.com")。但是在我从 Web 应用程序获得响应之前就发生了错误。
    • 您是否尝试过在您的租户中使用不同的站点 URL?类似于 ClientContext As New ClientContext("{DifferentSiteURL}").
    • 嗨@Guruparan,我设法通过引用ClaimsAuth.dll 让它工作。我从code.msdn.microsoft.com/sharepoint/…找到了dll文件
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-07
    • 1970-01-01
    • 1970-01-01
    • 2013-03-11
    相关资源
    最近更新 更多