📄 default.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using SqlAdmin;
namespace SqlWebAdmin {
/// <summary>
/// Summary description for Login.
/// </summary>
public class Login : System.Web.UI.Page {
protected System.Web.UI.WebControls.TextBox ServerTextBox;
protected System.Web.UI.WebControls.TextBox PasswordTextBox;
protected System.Web.UI.WebControls.TextBox UsernameTextBox;
protected System.Web.UI.WebControls.Button LoginButton;
protected System.Web.UI.WebControls.Label ErrorLabel;
protected System.Web.UI.WebControls.Label LogoutInfoLabel;
protected System.Web.UI.WebControls.RequiredFieldValidator UsernameRequiredFieldValidator;
protected System.Web.UI.WebControls.RequiredFieldValidator ServerRequiredFieldValidator;
protected System.Web.UI.WebControls.Label LoginInfoLabel;
public Login() {
Page.Init += new System.EventHandler(Page_Init);
}
private void Page_Load(object sender, System.EventArgs e) {
if (!IsValid)
return;
if (ServerTextBox.Text != null && ServerTextBox.Text.Length == 0) {
ServerTextBox.Text = "localhost";
}
ErrorLabel.Visible = false;
LogoutInfoLabel.Visible = false;
LoginInfoLabel.Visible = false;
if (Request["error"] != null) {
switch (Request["error"]) {
case "sessionexpired":
ErrorLabel.Text = "Your session has expired or you have already logged out. Please enter your login info again to reconnect.";
break;
case "userinfo":
ErrorLabel.Text = "Invalid username and/or password, or server does not exist.<br>Also, please ensure that SQL Server Authentication is enabled on the server.";
break;
default:
ErrorLabel.Text = "An unknown error occured.";
break;
}
ErrorLabel.Visible = true;
}
else if (Request["action"] == "logout") {
LogoutInfoLabel.Visible = true;
}
else {
LoginInfoLabel.Visible = true;
}
}
private void Page_Init(object sender, EventArgs e) {
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
}
#region Web Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent() {
this.LoginButton.Click += new System.EventHandler(this.LoginButton_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void LoginButton_Click(object sender, System.EventArgs e) {
if (!IsValid)
return;
SqlServer server = new SqlServer(ServerTextBox.Text, UsernameTextBox.Text, PasswordTextBox.Text);
if (server.IsUserValid()) {
// Create cookie and add session information to it
HttpCookie cookie = new HttpCookie("WebDataAdministrator");
cookie.Values.Add("username", server.Username);
cookie.Values.Add("password", server.Password);
cookie.Values.Add("server", server.Name);
Response.Cookies.Add(cookie);
Response.Redirect("databases.aspx");
}
else {
ErrorLabel.Visible = true;
ErrorLabel.Text = "Invalid username and/or password, or server does not exist.<br>Also, please ensure that SQL Server Authentication is enabled on the server.";
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -