2009年8月12日 星期三

清除DNS Cache

※清除DNS Cache

◎Window系列


ipconfig /flushdns


◎Linux系列


service nscd restart


◎Mac系列


lookupd -flushcache


2009年8月4日 星期二

ASP使用AD的LDAP做登入驗證

以下插入<head>

<%
MM_LoginAction = Request.ServerVariables("URL")
If Request.QueryString <> "" Then MM_LoginAction = MM_LoginAction + "?" + Server.HTMLEncode(Request.QueryString)
'#驗證的帳號表單
MM_valUsername = CStr(Request.Form("userid"))
If MM_valUsername <> "" Then
Dim MM_fldUserAuthorization
Dim MM_redirectLoginSuccess
Dim MM_redirectLoginFailed
dim strpassword,domainname
dim objDomain,objADsPath,objConnection,objCommand,objRS

MM_fldUserAuthorization = ""
'#驗證成功後前往的頁面
MM_redirectLoginSuccess = "LoginSuccess.asp"
'#驗證失敗後前往的頁面
MM_redirectLoginFailed = "LoginFailed.asp"
'#驗證的密碼表單名稱
strpassword=Request.Form("passwd")
'#驗證網域名稱,EX:domain.com,填入domain即可
domainname="domain"

on error resume next

Set objDomain = GetObject ("GC://rootDSE")
objADsPath = objDomain.Get("defaultNamingContext")
Set objDomain = Nothing
Set objConnection = Server.CreateObject("ADODB.Connection")
objConnection.provider ="ADsDSOObject"
objConnection.Properties("User ID") = domainname+"\"+MM_valUsername
objConnection.Properties("Password") = strpassword
objConnection.open "Active Directory Provider"
Set objCommand = CreateObject("ADODB.Command")
Set objCommand.ActiveConnection = objConnection
objCommand.CommandText ="select cn FROM 'GC://"+objADsPath+"' where sAMAccountname='"+MM_valUsername+"'"
Set objRS = objCommand.Execute

If Err.Number = 0 Then
'#驗證成功後產生帳號的Session
Session("MM_Username") = MM_valUsername
Response.Redirect(MM_redirectLoginSuccess)
else
Response.Redirect(MM_redirectLoginFailed)
End if
End if
%>

</head>


以下插入<body>

<form id="form2" name="form1" method="POST" action="<%=MM_LoginAction%>">
<p align="center">帳號:
<label>
<input name="userid" type="text" id="userid" />
</label>
</p>
<p align="center">密碼:
<label>
<input type="password" name="passwd" id="passwd" />
</label>
</p>
<p align="center">
<label>
<input type="submit" name="login" id="login" value="送出" />
</label>
<label>
<input type="reset" name="clean" id="clean" value="重設" />
</label>
</p>
</form>


</body>

##EasyReadMore##