欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-05-27 21:53:31
图3 config.web文件 <?xml version="1.0" encoding="utf-8" ?> <configura...
图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.x"
    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