日期:2014-05-18  浏览次数:20547 次

命名空间并不直接包含诸如字段或方法之类的成员
namespace   WebApplication1.Modules
{
using   System;
using   System.Data;
using   System.Drawing;
using   System.Web;
using   System.Web.UI.WebControls;
using   System.Web.UI.HtmlControls;
using   System.Web.Security;

///   <summary>
/// LogonModule   的摘要说明。
///   </summary>
public   class   LogonModule   :   System.Web.UI.UserControl
{
protected   System.Web.UI.WebControls.TextBox   LogonNameTextBox;
protected   System.Web.UI.WebControls.TextBox   LogonPasswordTextBox;
protected   System.Web.UI.WebControls.RequiredFieldValidator   LogonNameRequiredFieldValidator;
protected   System.Web.UI.WebControls.RequiredFieldValidator   LogonPasswordRequiredFieldValidator;
protected   System.Web.UI.WebControls.ValidationSummary   LogonValidationSummary;
protected   System.Web.UI.WebControls.Button   LoginButton;
protected   System.Web.UI.WebControls.Label   ShowMsg;
protected   System.Web.UI.WebControls.Label   Label1;

private   void   Page_Load(object   sender,   System.EventArgs   e)
{
if(HttpContext.Current.User.Identity.IsAuthenticated)
{
String   UserName=HttpContext.Current.User.Identity.Name;
String   Type=null;
if(UserType.ToString()== "1 ")

Type= " <b> <font   color= 'red '> 系统管理员 </font> </b> ";
else   if(UserType.ToString()== "2 ")
  Type= " <b> <font   color= 'red '> 普通用户 </font> </b> ";
ShowMsg.Text= " <b> <font   color= 'red '> "+UserName+ " </font> </b> ,欢迎进入本系统,用户类型为: "+Type;
ShowMsg.Style[ "color "]= "Green ";
}
else
{
ShowMsg.Text= "您还未登录本系统,登陆后才可使用各项服务 ";
ShowMsg.Style[ "color "]= "Red ";
}
}
}

#region   Web   窗体设计器生成的代码
override   protected   void   OnInit(EventArgs   e)
{
//
//   CODEGEN:   该调用是   ASP.NET   Web   窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

///   <summary>
/// 设计器支持所需的方法   -   不要使用代码编辑器
/// 修改此方法的内容。
///   </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(Authenticate(LogonNameTextBox.Text.Trim(),LogonPasswordTextBox.Text.Trim())==true)
{
FormsAuthentication.SetAuthCookie(LogonNameTextBox.Text.Trim(),false);
Response.Redirect(PathPrefix+ "/default.aspx ");
}
else
{
Label1.Visible=true;
}
}
}



------解决方案--------------------
把字段或方法之类的成员全部放在class中