2017-03-28 1 views
0

전적으로 Sharepoint Online을 vb.net 프로그램과 연결하는 데있어 새로운 조언이 될 것입니다.VB.net을 사용하여 Sharepoint Online에 대한 사용자 인증

나는 2 .DLL 파일에 대한 참조, Microsoft.Sharepoint.ClientMicrosoft.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 "[email protected]".ToCharArray() 
      password.AppendChar(c) 
     Next 


     ClientContext.Credentials = New SharePointOnlineCredentials("[email protected]", password) 
     Dim web As Web = ClientContext.Web 

     ClientContext.Load(web) 
     ClientContext.ExecuteQuery() 

    End Using 
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()에 명중합니다 오류가

An exception of type 'System.Net.WebException' occurred in Microsoft.SharePoint.Client.dll but was not handled in user code

Additional information: The remote server returned an error: (403) Forbidden.

입니다 인증 문제로 인한 것으로 알고 있습니다. , Sharepoint url은 회사의 허가 된 사용자를위한 것입니다. 코드의 자격 증명이 권한이 부여 된 사용자에게 속한다고 가정합니다.

코딩이 잘못되었거나 기업 IT 보안 정책이 원인 일 수 있습니까?

답변

0

변경 새로운 ClientContext으로 ClientContext를 사용하여 라인 ("https://sample.sharepoint.com/Home.aspx")

새로운 ClientContext으로 ClientContext를 사용 에 ("https://sample.sharepoint.com") 당신이 ClientContext로를 사용하여 다른 사이트 사용 를 사용하려는 경우 새 ClientContext ("https://sample.sharepoint.com/sites/yoursite")

페이지를 사용하여 사이트에 연결하지 마십시오.

+0

안녕하세요 @ 구루 빠란, 답장을 보내 주셔서 감사합니다. 그리고 아니, 그것은 여전히 ​​나에게 403 오류를 제공합니다. –

+0

@TanStanley 사이트 URL을 바꿔 넣으시겠습니까? https://sample.sharepoint.com –

+0

테스트 목적으로 새 ClientContext ("https://sample.sharepoint.com")로 ClientContext를 사용했습니다. 그러나 웹 응용 프로그램에서 응답을 얻을 수 있기 전에 오류가 발생합니다. –

관련 문제