NET移植案例学习:建造Web站点(6)

来源:互联网 发布:淘宝提升排名方法 编辑:程序博客网 时间:2024/06/08 19:41
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
document.write(baiduCproIFrame());--> 图3Config.Web文件

<?xmlversion="1.0"encoding="utf-8"?>
<configuration>

 <!--SECURITY
Thissectionsetsthesecuritypoliciesoftheapplication.
Possiblemodesare"Windows","Cookie",
"Passport"and"None"
 -->

 <!--UseCookieAuthenticationforexternalusers-->


 <security>
<authenticationmode="Cookie">
 <cookiecookie=".PRODAUTH"loginurl="https://
 beta.visualstudio.NET/Login.aspx"
decryptionkey="autogenerate">

<credentialspasswordformat="Clear"/>
 </cookie>
</authentication>
<authorization>
 <allowusers="*"/>
</authorization>
 </security>
</configuration>


图4认证代码

PublicSubcmdSubmit_Click(ByValsenderAsObject,ByValeAs_
System.EventArgs)
 DimsUserIDAsString
 DimsPasswordAsString
 DimsAuthCookieAsString

 'Externaluser,takethevaluesfromtheLoginform
 sUserid=system.Convert.ToString(Me.txtUserID.Value)
 sPassword=system.Convert.ToString(Me.txtPassword.Value)

 adoRS=oBetaUser.LoginEx(sUserID,sPassword)

 IfadoRS.recordcount=1Then
'loginsuccess-getasession
adoRS=osSession.GetNewSession_
(adoRS("BetaSiteID").Value.ToString().ToInt32())

IfNotadoRSIsNothingThen
 IfadoRS.Recordcount>0Then
adoRS.movefirst()

'SettheauthenticationcookieusingtheSID
sAuthCookie=adoRS("SID").Value.ToString()

'useASP+authenticationtoauthenticatetheuser,
IfInstr(CookieAuthentication.GetRedirectUrl_
 (sAuthCookie,True),"default.aspx")>0Then
 CookieAuthentication.SetAuthCookie(sAuthCookie,True)
 Response.Redirect(system.Convert.ToString(_
oSiteUser.GlobalPath)&"Home.aspx")
Else
 CookieAuthentication.RedirectFromLoginPage(_
 sAuthCookie,True)
EndIf
 Else
'loginfailed
Response.Redirect("LoginFailed.aspx")
 EndIf
Else
 'loginfailed
 Response.Redirect("LoginFailed.aspx")
EndIf
 Else
'loginfailed
Response.Redirect("LoginFailed.aspx")
 EndIf
EndSub

<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>