请问,在vc#中 如果要限制别人登陆后才能进入如何做? 这个在asp.net版面提一个是可以在webconfig设置,另一个就是要在每一个页面中检测!好长时间不用asp.net给忘了!帮你顶一下! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 做一个验证模块,该模块中可以做用户验证授权(票据验证,客户端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> 利用asp.net身分验证票来解决验证问题具体讲起来很复杂请参考《ASP.NET安全性高级编程》(Wrox)清华大学出版以及利用vs2003合并集合察看类IPrincipal以及IIdentity==========================================================================说假话,我不是C#高手 哦 我不是这意思! 我说的做的桌面软件, 不是说的asp.net ! 明白否! 大哥!!!!!!!!!!!!!!!! 一个Singleton模式就可以了!!设计模式!用它保存你的当前客户信息。相当于Session了吧? 基类虚方法的重载 输入一个日期,要求大于等于今天的正则表达式,如何写. 这种情况怎么添加节点? 怎么把查询到的数据写入xsd里的表? 结果求解释(关于接口、继承、多态)! C#窗口大小变化能否知道变化原因(双击标题栏或者鼠标移动各个边框) 有关c#操作xml的问题,希望大家来给点意见 异步socket通讯的缓冲区问题 SetWindowPlacement 这个API在C#中怎样调用? 请教c# 怎样读写INI文件? 请问c#语言容易被反向编译吗?可读性怎么样?怎样保护自己的程序代码? asp.net 分頁查詢結果顯示的功能
{
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>
具体讲起来很复杂
请参考《ASP.NET安全性高级编程》(Wrox)清华大学出版
以及利用vs2003合并集合察看类
IPrincipal以及
IIdentity==========================================================================
说假话,我不是C#高手
用它保存你的当前客户信息。
相当于Session了吧?