2011-10-31 48 views
0

是否有一種方法可以爲面向公衆的站點進行簡單的Windows身份驗證(匿名查看已啓用以便查看登錄頁面)但彈出窗口在windows auth對話框中,使用登錄頁面(aspx)。當我切換到混合模式身份驗證時,我看到類似的東西。 SharePoint具有「windows身份驗證」或「表單身份驗證」的下拉菜單。我需要的是類似的東西,但只是「Windows身份驗證」選項。有Windows身份驗證使用默認登錄頁面,而不是彈出對話框在Sharepoint 2010

我看過類似的問題,但都涉及到創建自定義登錄頁面。理想的解決方案將不涉及新的頁面,也不涉及編碼。

這可能嗎?

回答

1

這可以通過在Internet Explorer中啓動sharepoint頁面的地址並使用一些pinvoke api將密鑰或settext發送到登錄框來完成。

我對vb.net表單應用程序的這個設置進行了擴展。它適用於我的XP。我還沒有在Windows 7中嘗試過,但我相信它需要一些調整才能在那裏工作。

它使用一個名爲WindowScraper庫,從這裏開始:http://www.programmersheaven.com/download/56171/download.aspx

該庫有一堆WINAPI和PInvoke的內置如果你的組件將不會允許它(因爲你使用VS 2010,也許)。稱它沒有強名,然後使用SharpDevelop並在添加自己的證書後重建解決方案。

然後將dll放到您的應用程序目錄中並添加一個引用。

然後添加進口:

Imports WindowScrape 
Imports WindowScrape.Constants 
Imports WindowScrape.Types 

最後,該代碼(把所有的模塊或類):

私有財產PortalAddress的String =「HTTP:// myportal @地方。 COM」 私有財產logintitle的String = 「連接到[email protected]

公用Sub openPortal()

If My.Computer.Info.OSFullName = "Microsoft Windows XP Professional" then 
    LoginToPortalXP() 
Else 
    msgbox("Someday, we will be able to log you in automatically" & vbCr & "But it isn't ready yet.") 
End If 
End Sub 

Private Function IsWindowReady(Optional ByVal timeout As integer = 10000) 
    Dim isready As Boolean = false 
    Dim timer As Integer = 1000 
    Do Until Not loginBox is nothing or timer = timeout 
     Thread.Sleep(1000) 
     loginbox = HwndObject.GetWindowByTitle(logintitle) 
     timer = timer + 1000 
    loop 
    If Not loginbox is nothing then isready = true 
    Return isready 
End Function 

Sub LoginToPortalXP() 
    Try 
     Dim TheBrowser As Object = CreateObject("InternetExplorer.Application") 
     TheBrowser.Visible = True 
     TheBrowser.Navigate(PortalAddress) 
     If Not IsWindowReady then debug.print("failed") : Exit sub 

     Dim sys As HwndObject = loginbox.GetChildren(1) 'SysCredential 
     sys.GetChildren(1).Text = "myUserName" 'username box 
     Thread.Sleep(500) 
     sys.GetChildren(4).Text = "myPassword" 'password box 
     Thread.Sleep(500) 
     loginbox.GetChildren(2).Click()  'push the okay button 
    Catch ex As Exception 
     msgbox("ERROR AutoLogging into Portal: " & vbcr & & ex.Message) 
    Finally   
    End Try 
End Sub 

我增加了計時器,以防萬一需要更長的時間。當然,您可以更改超時時間。

+0

你好@BGM,謝謝你的回覆。但是,我希望有一點「黑客」,使用更多的函數構建。也許我正在尋找的答案並不存在。無論如何,我真的很喜歡這個創意和你採取的方法,並提高了答案。但是不要以爲我能給出最終答案呢。再次感謝。 – mateuscb

+0

@mateuscb嗯,我想說,我一直在尋找方法來做這個幾年。我發現的唯一方法就是這種「哈克」方式。我已經在autohotkey中編寫了另一個腳本,它執行相同的操作,但允許您選擇一個帳戶進行登錄,並且它也可以在Firefox中使用。上面的方法適用於dotnet,除了dotnet和api之外沒有任何其他方法。實際上它工作得很好。唯一的缺點是如果MS更改控件的順序。另外,我只在XP和Sharepoint Services 2007上試過它;我正在爲Windows7工作。 – bgmCoder

+0

再次感謝@BGM! – mateuscb

相關問題