我有一個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