2024年4月10日发(作者:)
注: 适用于客户机已经加入域
1、首先新建一个页面():
前台代码(
):
<%@ Page Language="C#" AutoEventWireup="true" CodeFile=""
Inherits="Login" %>
"/TR/xhtml1/DTD/">
后台代码(
):
using System;
using ;
using uration;
using tions;
using ;
using ty;
using ;
using trols;
using ts;
using ntrols;
public partial class Login :
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Login_Click(object sender, EventArgs e)
{
string adPath = "LDAP://" + ;
LdapAuthentication adAuth = new LdapAuthentication(adPath);
try
{
if (true == enticated(, ,
))
{
string groups = upByUser();
//Create the ticket, and add the groups.
bool isCookiePersistent = d;
FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1,
, , utes(60),
isCookiePersistent, groups);
//Encrypt the ticket.
string encryptedTicket = t(authTicket);
//Create a cookie, and then add the encrypted ticket to the cookie as data.
HttpCookie authCookie = new
HttpCookie(ookieName, encryptedTicket);
if (true == isCookiePersistent)
s = tion;
//Add the cookie to the outgoing cookies collection.
(authCookie);
//You can redirect now.
ct(irectUrl(,
false));
}
else
{
= "Authentication did not succeed. Check user name and
password.";
发布评论