我有一个web项目图形用户界面..表单登录访客和管理员问题
我第一次使用管理员只。
因此,当管理员用他的用户名和密码登录时,我使用表单身份验证将他重定向到默认页面“Default.aspx”。
但现在我有客人工作... ...并会在登录
检查的作用,如果它是一个客人然后重定向他做客页面不是“Default.aspx的”
具有只读权限......如他不应该能够使数据库的任何变化,即使有
我正在使用此代码的选项:
public partial class Login : System.Web.UI.Page
{
public const int LOGON32_LOGON_INTERACTIVE = 2;
public const int LOGON32_PROVIDER_DEFAULT = 0;
WindowsImpersonationContext impersonationContext;
[DllImport("advapi32.dll")]
public static extern int LogonUserA(String lpszUserName,
String lpszDomain,
String lpszPassword,
int dwLogonType,
int dwLogonProvider,
ref IntPtr phToken);
[DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern int DuplicateToken(IntPtr hToken,
int impersonationLevel,
ref IntPtr hNewToken);
[DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool RevertToSelf();
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern bool CloseHandle(IntPtr handle);
}
protected void LoginButton_Click(object sender, EventArgs e)
{
IntPtr token = IntPtr.Zero;
IntPtr tokenDuplicate = IntPtr.Zero;
if (LogonUserA(UserName.Text, Domain.Text, Password.Text, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, ref token) != 0)
{
if (impersonateValidUser(UserName.Text, Domain.Text, Password.Text) == true)
{
Label1.Text = "impersonation";
}
else
{
Label2.Text = "not impersonating";
}
//impersonateValidUser(UserName.Text, Domain.Text, Password.Text);
System.Security.Principal.WindowsIdentity wi = System.Security.Principal.WindowsIdentity.GetCurrent();
System.Security.Principal.WindowsPrincipal wp = new System.Security.Principal.WindowsPrincipal(wi);
if (wp.IsInRole("Administrators"))
{
BadCredentials.Visible = false;
Session["userName"] = UserName.Text;
Session["password"] = Password.Text;
Session["domain"] = Domain.Text;
FormsAuthentication.RedirectFromLoginPage(UserName.Text, false);
}
else if(wp.IsInRole("Guest"))
{
?? I want to redirect it to the guestpage.aspx and not the default.aspx
}
}
else
{
BadCredentials.Visible = true;
Label4.Text = "not valid user";
}
}
private bool impersonateValidUser(String userName, String domain, String password)
{
WindowsIdentity tempWindowsIdentity;
IntPtr token = IntPtr.Zero;
IntPtr tokenDuplicate = IntPtr.Zero;
if (RevertToSelf())
{
if (LogonUserA(userName, domain, password, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, ref token) != 0)
{
if (DuplicateToken(token, 2, ref tokenDuplicate) != 0)
{
tempWindowsIdentity = new WindowsIdentity(tokenDuplicate);
impersonationContext = tempWindowsIdentity.Impersonate();
if (impersonationContext != null)
{
CloseHandle(token);
CloseHandle(tokenDuplicate);
return true;
}
}
}
}
if (token != IntPtr.Zero)
CloseHandle(token);
if (tokenDuplicate != IntPtr.Zero)
CloseHandle(tokenDuplicate);
return false;
}
这对我来说很重要...任何建议将理解..感谢
有在SQL或IIS一些stiing为只读模式游客????
我在webconfig
<authentication mode="Forms">
<forms loginUrl="Login.aspx" defaultUrl="~/Default.aspx" name="Cookie" timeout="120" path="/">
</forms>
</authentication>
<authorization>
<deny users="?"/>
<allow users="*"/>
</authorization>
用这个和这个工程..
我实际上正在做表单身份验证,但要查看用户是否是管理员电脑我使用了一些Windows属性...我不知道如何检查它在表单认证...如果你可以建议一些更好的方式,我会感激它......谢谢..我实际上使用这在我的webconfig,它的工作原理 <认证模式= “表单”> <形式loginUrl = “的Login.aspx” defaultUrl = “〜/ Default.aspx的” 名称= “曲奇” 超时= “120” 路径= “/”> 验证> <授权> <拒绝用户=“?“/> authorization> –
user175084
2010-01-08 22:07:11
如果没有”windows“帐户,您无法看到它们是否是机器上的guest,guest是特定的windows帐户。 * do是检查用户是否在数据库中的预定义组中,如果不是,他们自动是“访客”。 – GrayWizardx 2010-01-08 22:16:02