我想做一个用户信息验证的,就不知ASP.net如何调用C#做的组件,请那位大虾赶紧帮帮我

chenxf66 2004-07-29 02:53:42
现在想让用户在login.aspx页面上的用户登录栏输入信息后(用户输入框:user;密码输入框password),调用组件login.dll进行信息验证,然后把结果反馈到另外一个页面member.aspx,如果错误就让用户重新输入,如果没错则显示该用户的信息。
我用的是SQL数据库,Provider=SQLOLEDB;PWD=123;UID=sa;DATABASE=member;DATA SOURCE="127.0.0.1",用户表为user,字段为usename和password
** 上面的用户登录栏不是和组件合在一起的,只是用来调用组件
** 请问整个过程是如果调用组件,组件又是如何写,接着是如何把信息返馈给另一个页面
...全文
79 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
possible_Y 2004-10-06
  • 打赏
  • 举报
回复
在web.config里还需做如下配置:

使用我们自己验证:
<authentication mode="None"/>

拒绝匿名用户访问
<authorization>
<deny users="?"/>
</authorization>

login.aspx则允许匿名访问:
<location path="login.aspx">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>

possible_Y 2004-10-06
  • 打赏
  • 举报
回复
using System;
using System.Web;
using System.Security.Principal;

namespace SecurityModules
{
public class CustomAuthenticationModule : IHttpModule
{
public CustomAuthenticationModule()
{
}
public void Init(HttpApplication r_objApplication)
{
r_objApplication.AuthenticateRequest += new EventHandler(this.AuthenticateRequest) ;
}

public void Dispose()
{
}

private void AuthenticateRequest(object r_objSender,
EventArgs r_objEventArgs)
{
HttpApplication objApp = (HttpApplication) r_objSender ;
HttpContext objContext = (HttpContext) objApp.Context ;
if ( (objApp.Request["userid"] == null) || (objApp.Request["password"] == null) )
{
objContext.Response.Redirect("member.aspx?msg=error", false);
objContext.Response.End();
}

string userid = "" ;
userid = objApp.Request["user"].ToString() ;
string password = "" ;
password = objApp.Request["password"].ToString() ;

string[] strRoles ;
strRoles = AuthenticateAndGetRoles(userid, password) ;
if ((strRoles == null) || (strRoles.GetLength(0) == 0))
{
objContext.Response.Redirect("member.aspx?msg=error", false);
objContext.Response.End();
}

GenericIdentity objIdentity = new GenericIdentity(userid,"CustomAuthentication") ;
objContext.User = new GenericPrincipal(objIdentity, strRoles) ;
objContext.Response.Redirect("member.aspx?msg=succeed", false);
}

//这个函数你可以自己改为从数据库里捞数据来匹配
private string[] AuthenticateAndGetRoles(string r_strUserID,string r_strPassword)
{
string[] strRoles = null ;
if ((r_strUserID.Equals("possible")) && (r_strPassword.Equals("123456")))
{
strRoles = new String[1] ;
strRoles[0] = "Administrator" ;
}
else
{
if ((r_strUserID.Equals("csdn")) && (r_strPassword.Equals("csdn")))
{
strRoles = new string[1] ;
strRoles[0] = "User" ;
}
}
return strRoles ;
}
}
}

在web.config里注册:
<httpModules>
<add type="classname, assemblyname" name="modulename" />
<httpModules>


在member.aspx里就可以根据msg来判断是否成功登陆,并从Page.User来获得用户的帐号和用户类型(Administrator或User)
dandantree 2004-10-06
  • 打赏
  • 举报
回复
关注
possible_Y 2004-10-06
  • 打赏
  • 举报
回复
仔细再看了看楼主的描述,是乎是要把用户名和密码直接提交个这个dll处理
那么需要写一个HTTP Modules
possible_Y 2004-10-06
  • 打赏
  • 举报
回复
单独建一个工程,写一个类,里面有一个验证函数,接受2个string的参数:用户名和密码,返回一个bool值,表示验证是否通过....
denoxo 2004-10-06
  • 打赏
  • 举报
回复
关注

62,266

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧