明白了。在Web Matrix中,打开NuGet软件包管理器并安装Novell.Directory.Ldap软件包。下面是一个示例用法:
@using Novell.Directory.Ldap;
@{
Validation.RequireField("username", "username is required");
Validation.RequireField("password", "password is required");
var username = "";
var userdn = "";
var domain = "domain.com";
var pwd = "";
var error = "";
if (IsPost) {
if (Validation.IsValid()) {
username = Request["username"];
userdn = "cn=" + username + ",ou=Users,o=INTRANET";
pwd = Request["password"];
try {
LdapConnection ldapConnection = new LdapConnection();
ldapConnection.Connect(domain, 389);
ldapConnection.Bind(userdn, pwd);
}
catch (LdapException e) {
error = e.LdapErrorMessage;
}
}
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Hello LDAP Page</title>
</head>
<body>
<h1>Hello LDAP Page</h1>
@if (IsPost) {
if (error.IsEmpty()) {
<p>'@username' was successfully authenticated against <i>@domain</i>!</p>
}
else {
<p>error! @error</p>
}
}
else {
@Html.ValidationSummary()
<form method="post">
<fieldset>
<legend>Login</legend>
<p><label for="username">Username:</label>
<input type="text" name="username" value="" />
@Html.ValidationMessage("title")</p>
<p><label for="password">Password:</label>
<input type="password" name="password" value="" />
@Html.ValidationMessage("password")</p>
<p><input type="submit" name="buttonSubmit" value="Login" /></p>
</fieldset>
</form>
}
</body>
</html>
你有什么试过或者你到目前为止得到了什么..?你是否熟悉'PrincipalContext' ..在这里你可以找到很多工作示例[C#PrincipalContext示例](http://www.google.com) – MethodMan 2015-02-05 19:40:33
我用'+ Razor Active Directory ASP.NET'搜索了Google,这是第二次打击:http://forums.asp.net/t/1851715.aspx?MVC3+C+using+razor+with+ldap+active+directory+Authentication – 2015-02-05 19:45:58
我正在寻找的解决方案将排除编写一个C#类在Visual Studio中。例如,我希望在Web Matrix中有一个内置的Helper(例如像WebSecurity助手)。也许它不存在,我需要使用C#/ VS的其中一个示例自己创建一个Helper,然后将其导入到Web Pages项目中。 – lucid 2015-02-05 19:53:02