圖3 Config.web文件
<?XML version="1.0" encoding="utf-8" ?>
<configuration>
<!-- SECURITY
This section sets the security policIEs of the application.
Possible modes are "Windows", "CookIE",
"Passport" and "None"
-->
<!-- Use CookIE Authentication for external users -->
<security>
<authentication mode="CookIE">
<cookie cookIE=".PRODAUTH" loginurl="https://
beta.visualstudio.Net/Login.ASPx"
decryptionkey="autogenerate">
<credentials passWordformat="Clear" />
</cookIE>
</authentication>
<authorization>
<allow users="*" />
</authorization>
</security>
</configuration>
圖4 認證代碼
Public Sub cmdSubmit_Click(ByVal sender As Object, ByVal e As _
System.EventArgs)
Dim sUserID As String
Dim sPassWord As String
Dim sAuthCookIE As String
'External user, take the values from the Login form
sUserid = system.Convert.ToString(Me.txtUserID.Value)
sPassword = system.Convert.ToString(Me.txtPassWord.Value)
adoRS = oBetaUser.LoginEx(sUserID, sPassWord)
If adoRS.recordcount = 1 Then
'login success - get a session
adoRS = osSession.GetNewSession _
(adoRS("BetaSiteID").Value.ToString().ToInt32())
If Not adoRS Is Nothing Then
If adoRS.Recordcount > 0 Then
adoRS.movefirst()
'Set the authentication cookIE using the SID
sAuthCookIE = adoRS("SID").Value.ToString()
'use ASP+ authentication to authenticate the user,
If Instr(CookIEAuthentication.GetRedirectUrl _
(sAuthCookIE, True), "default.ASPx") > 0 Then
CookieAuthentication.SetAuthCookie(sAuthCookIE, True)
Response.Redirect(system.Convert.ToString( _
oSiteUser.GlobalPath) & "Home.ASPx")
Else
CookIEAuthentication.RedirectFromLoginPage( _
sAuthCookIE, True)
End If
Else
'login failed
Response.Redirect("LoginFailed.ASPx")
End If
Else
'login failed
Response.Redirect("LoginFailed.ASPx")
End If
Else
'login failed
Response.Redirect("LoginFailed.ASPx")
End If
End Sub