大家在编写网站中的管理部分时,如何来验证用户是否已登录?我看了一写网上下的整站程序,他们都是在后台编码文件的page_load中来判断session值的,
如果是这样,那么假如我要加一个session验证,或减少一个session验证,我岂不是所有的文件都要改?在asp中可以通过包含一个公共的验证文件来验证,如果session需要改动,只要改这一个文件就行了,那么在asp.net中应该如何做呢?

解决方案 »

  1.   

    自己写个类,需要判断session的时候都去调用它
      

  2.   

    不大明白楼主所说,我用的也是在Page_load事件中判断session值是否存在。
      

  3.   

    参考public string GetParaValue(HttpSessionState oSession, HttpRequest oRequest,string paraName)
    {
    string strValue="";

    //如果Session中能够找到相应的参数值,则返回参数值
    try
    {
    strValue=oSession[paraName].ToString();
    }
    catch(NullReferenceException)
    {
    strValue="";
    }
    //如果Session中不存在,从Request中寻找。
    if (ValidateUtil.isBlank(strValue))
    {
    try
    {
    strValue=oRequest[paraName].ToString();
    }
    catch(NullReferenceException)
    {
    strValue="";
    }
    //均为空时,返回空字符串。
    if (ValidateUtil.isBlank(strValue))
    strValue="";
    } return strValue;
    }
      

  4.   

    http://www.microsoft.com/china/technet/security/guidance/secmod18.mspx
      

  5.   

    Session,就这么简单,当然要设置好Session的有效时间的长短,在Web.Config里面
      

  6.   

    .net里不是提供很简单的了吗.
     登陆时先用FormsAuthentication.SetAuthCookie创建票据验证.
    然后在golbal.asax中, Application_AuthenticateRequest {            if (Request.IsAuthenticated == true) 
    这样判断。.