这个在asp.net版面提
一个是可以在webconfig设置,另一个就是要在每一个页面中检测!
好长时间不用asp.net给忘了!
帮你顶一下!

解决方案 »

  1.   

    做一个验证模块,该模块中可以做用户验证授权(票据验证,客户端cookie验证等)namespace ManagementSystem.SystemFramework
    {
    using System;
    using System.Web;
    using System.Text;
    using System.Data;
    using System.Web.Security;
    using System.Security.Principal; using ManagementSystem.Entity;
    using ManagementSystem.ApplicationLayer;
    /// <summary>
    /// 类AccreditModule提供客户端用户登陆授权管理。
    /// </summary>
    public class AuthenticateModule : IHttpModule
    {
    /// <summary>
    /// 继承自IHttpModule接口的处理票据验证请求的方法
    /// </summary>
    /// <param name="obj">托管对象</param>
    /// <param name="e">托管事件</param>
    public void OnAuthenticateRequest( object obj, EventArgs e )
    {
    HttpContext context = HttpContext.Current;
    String requestPage = context.Request.Url.ToString().Substring(context.Request.Url.ToString().LastIndexOf('/')+1); if( context.User != null )
    {
    if( context.User.Identity.IsAuthenticated )
    {
    if( context.User.Identity is FormsIdentity )
    {
    FormsIdentity identity = context.User.Identity as FormsIdentity;
    FormsAuthenticationTicket ticket = identity.Ticket;
    String[] role = ticket.UserData.ToString().Split(',');
    context.User = new GenericPrincipal( identity, role );
    Int32 nResult = AuthenticateModule.IsInRole( requestPage );
    if( nResult == 0 )
    context.Response.Redirect( "~/Login.aspx", true ); }
    }
    }
    else
    {
    if( AuthenticateModule.IsSetPopedom( requestPage ) )
    context.Response.Redirect( "~/Login.aspx" );
    }

    } /// <summary>
    /// 检查用户是否有权先访问授权页面
    /// </summary>
    /// <param name="strPage">检查的页面</param>
    /// <param name="strRoles">用户角色</param>
    /// <returns>返回-1时表示此页面没有授权</returns>
    public static Int32 IsInRole( String strPage )
    {
    DataTable dt = (new PopedomSystem()).GetPagePopedom( strPage );
    if( dt != null )
    {
    foreach( DataRow row in dt.Rows )
    {
    if( row["type"].ToString().Equals("allow") && row["usertype"].ToString().Equals("roles"))
    {
    Int32 nIsInRole = 0;
    if( row["user"].ToString() != "*" )
    {
    String[] roles = row["user"].ToString().Split(',');
    foreach( String role in roles )
    {
    if(HttpContext.Current.User.IsInRole( role ))
    {
    nIsInRole = 1;
    break;
    }
    }
    }
    else
    nIsInRole = 1;
    return nIsInRole;
    }
    }
    }
    return -1;
    }
    /// <summary>
    /// 检查页面是否授权
    /// </summary>
    /// <param name="strPage">检查的页面</param>
    /// <returns>返回false时表示此页面没有授权</returns>
    public static bool IsSetPopedom( String strPage )
    {
    DataTable dt = (new PopedomSystem()).GetPagePopedom( strPage );
    if( dt != null )
    {
    foreach( DataRow row in dt.Rows )
    {
    if( row["type"].ToString().Equals("allow") && row["usertype"].ToString().Equals("roles"))
    {
    if( row["user"].ToString() != "*" )
    {
    return true;
    }
    else
    return false;
    }
    }
    }
    return false;
    } /// <summary>
    /// 在应用程序关闭时被调用,使模块执行所需的所有清理工作
    /// </summary>
    public void Dispose(){} /// <summary>
    /// 注册对由HttpApplication提供的某些事件的委托
    /// </summary>
    /// <param name="httpApp">对当前HttpApplication对象的引用</param>
    public void Init( HttpApplication httpApp )
    {
    httpApp.AuthenticateRequest += new EventHandler( this.OnAuthenticateRequest );
    }
    }
    }然后在web.config文件中配置该模块信息即:
     <httpModules>
          <add name="Authentication" type="ManagementSystem.SystemFramework.AuthenticateModule, ManagementSystem" />
          <add name="Error" type="ManagementSystem.SystemFramework.ErrorModule, ManagementSystem"/>
        </httpModules>
      

  2.   

    利用asp.net身分验证票来解决验证问题
    具体讲起来很复杂
    请参考《ASP.NET安全性高级编程》(Wrox)清华大学出版
    以及利用vs2003合并集合察看类
    IPrincipal以及
    IIdentity==========================================================================
    说假话,我不是C#高手
      

  3.   

    哦 我不是这意思!  我说的做的桌面软件, 不是说的asp.net !  明白否! 大哥!!!!!!!!!!!!!!!!
      

  4.   

    一个Singleton模式就可以了!!设计模式!
    用它保存你的当前客户信息。
    相当于Session了吧?