60分求谁能够教会我forms认证 感觉那个东西有点麻烦,可能是因为我是新手的问题,还不是太懂,比如说现在有2个文本框,一个是输入帐号,另外一个是密码,点登陆以后,froms 认证怎么记录这2个值?还要用session吗?怎么读?还有怎么在webconfig里设置??还有,登陆进去以后页面怎么判断你是否符合身份?感觉很难啊 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不要这么麻烦的,后台里面这样取值dim userName as string = textbox1.textdim userPassword as string = textbox2.text 账号做个记录就可以了,密码可以不做记录。。你问的应该是做判断的问题吧。直接这样比较就可以。在.cs页面下 protected void Button1_Click(object sender, EventArgs e) { if(TextBox1.Text== "数据库里的账号"&&TextBox2.Text== "数据库里的密码") { Session["login"]="True"//登陆标记 Response.Redirect("登陆成功页面!"); } }需要验证的页面加 if(Session["login"]!="True") Response.Redirect("进入地址"); 那不闲麻烦的话就弄和ASP一样的FORM认证。在提交页面<form action="go.aspx" method="get"> <input type="text" name="userName" id="textfield" /> <input type="text" name="userPsw" id="textfield2" /> <input type="submit" name="button" id="button" value="提交" /></form>go.aspx页面中接收值string userName=Request.Form["userName"].ToString();string userPsw=Request.Form["userPsw"].ToString(); cs代码中if (AdminManager.CheckLogin(m)) { string strRedirect = Request["ReturnUrl"]; System.Web.Security.FormsAuthentication.SetAuthCookie("AdminUser", true); if (strRedirect == null) Response.Redirect("~/Admin/Index.aspx"); Response.Redirect(strRedirect); } else { Message.ShowMessage(this,"用户名或密码错误!"); }根目录下Web.Config中<authentication mode="Forms"> <forms name="AdminUser" loginUrl="~/Admin/Login.aspx"></forms> </authentication>admin文件夹目录下Web.Config中<system.web> <authorization> <deny users="?"/> <allow users="AdminUser"/> </authorization> </system.web> 我现在也在弄呢 不过 转到~/Admin/Login.aspx页的时候 页面的样式都不起作用了不知道为啥 http://www.svnhost.cn/Download/Detail-49.shtml 完整的from认证:你要知道的:Request,Response,Session,asp.net 中的from认证个人觉得是有点麻烦了,说白了form认证就是通过发送页面的<from>子元素要有name属性接受页面通过Request.From[]取值,判断Session[]的过程。asp.net 中的认证机制,就是在web.config需要配置的,只不过对传统认证进行了包装的。 恩,可能是你把图片,还是css样式放在Admin文件夹下了,没有登陆当然不能访问了,我刚才也遇见这样的问题,现在结果了希望对你帮助 web.config文件添加:<authentication mode="Forms"> <forms name="forms" loginUrl="Login.aspx" protection="All" timeout="180" /> </authentication> <authorization> <deny users="?"/> <allow users ="*"/> </authorization>----------登录string username=txtname.Text.trim();string password=txtpassword.Text.trim();if(username=="aaaa" && password=="bbbbbb") { FormsAuthentication.RedirectFromLoginPage(username, false); }else{ Page.ClientScript.RegisterStartupScript(this.GetType(), "AlertMessage", "<script language=javascript>alert('用户名或密码错误!')</script>");}} 看看吧:http://www.cnblogs.com/luomingchao/articles/474674.html Form验证分为很多方式.先说下配置 <system.web> <authentication mode="Forms"> <forms defaultUrl="admin/default.aspx" loginUrl="login.aspx" name="test" path="/" protection="All" timeout="30"> <credentials passwordFormat="MD5"> <user name="" password=""/> </credentials> </forms> </authentication>指定登录后的页面为 admin/default.aspx,如果直接在地址栏中输入admin/default.aspx会直接转到login.aspx.接下来,你还要配置admin/default.aspx页面不允许匿名访问.我的做法是指定admin目录下的所有页面,都不允许匿名用户访问.这个配置如果你熟悉的话,可以直接在web.config中修改,如果不允许的话,可以启动 vs中的项目中的asp.net配置程序,来帮助你来配置.如果你的应用比较简单,就是说用户是依靠你来分配的,那么可以简单的新增user节点,以建立一些用户群.在验证用户身份时,可以这样 if(System.Web.Security.FormsAuthentication.Authenticate(Textbox1.Text,Textbox2.Text)) { // 做登录成功的操作 }这样在admin/default.aspx中,就可以使用Page.User.Identity.Name 来获取登录的用户名了.以上,只是Form验证中的一种.还有一种是配合数据库操作.还有一种是结合用户和角色的(不是指Membership API) 如果你的应用比较简单,就是说用户是依靠你来分配的,那么可以简单的新增user节点,以建立一些用户群. 补充一下,上述的说法不是太严谨,user节点是可以用程序来添加的.当然这样的做法是每添加一用户或修改password,该application会重启.当然也可以将authentication整个节点,建立在另一个web.config中,再以其它方式加载进来,这样的话,application是不会重启的,你也可以用程序来新增用户. <!-- 通过 <authentication> 节可以配置 ASP.NET 使用的 安全身份验证模式, 以标识传入的用户。 --> <authorization> <allow users="*"/> </authorization> <authentication mode="Forms"> <forms loginUrl="~/Logon.aspx" protection="All" timeout="30" name=".ASPXAUTH" path="/" requireSSL="false" slidingExpiration="true" cookieless="UseDeviceProfile" enableCrossAppRedirects="false"/> </authentication> <!-- 如果在执行请求的过程中出现未处理的错误, 则通过 <customErrors> 节可以配置相应的处理步骤。具体说来, 开发人员通过该节可以配置 要显示的 html 错误页 以代替错误堆栈跟踪。 <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm"> <error statusCode="403" redirect="NoAccess.htm" /> <error statusCode="404" redirect="FileNotFound.htm" /> </customErrors> --> </system.web> <location path="admin"><!--这里是要登录才能操作的页面文件夹名字--> <system.web> <authorization> <deny users="?"/> <allow users="*"/> </authorization> </system.web> </location></configuration>//“登录”按钮事件protected void btn_click(){ if(Login(strUserID, strUserPassword)) { if (Request.QueryString["ReturnUrl"] != null) { FormsAuthentication.RedirectFromLoginPage(username, false); } else { FormsAuthentication.SetAuthCookie(username, false); Response.Redirect("admin/Default.aspx", false); } } else Response.write("登录失败");}protected bool Login(string userid, string password){ bool islogin = false; //此处检查登录 return islogin;} 获取当前用户名 用string name=Page.User.Identity.Name Form验证是薄弱的。现在很多人在Form验证基础上利用私有数据变成基于Form角色验证机制 http://blog.csdn.net/eyu777/archive/2008/05/27/2487311.aspx给你参考下吧 Forms验证,多角色,多登录页 看我的LZ这个是webconfig<authentication mode="Forms"> <forms name=".Member" loginUrl="Manage/Login.aspx" protection="All" timeout="20"/> </authentication> <!-- 如果在执行请求的过程中出现未处理的错误, 则通过 <customErrors> 节可以配置相应的处理步骤。具体说来, 开发人员通过该节可以配置 要显示的 html 错误页 以代替错误堆栈跟踪。 <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm"> <error statusCode="403" redirect="NoAccess.htm" /> <error statusCode="404" redirect="FileNotFound.htm" /> </customErrors> --> <customErrors mode="Off" defaultRedirect="Error.aspx"> </customErrors> </system.web> <location path="Manage"> <system.web> <authorization> <deny users="?"/> <allow users="*"/> </authorization> </system.web> </location>这个是对我的管理员登陆的一个Form验证如果没有登陆的话就不能够访问管理后台(Manage文件夹下面)就这样就OK啦! 菜鸟求教~关于第三方控件SmartGridView的commandname绑定 想制作一个基于ASP.NET的大文件上传 dataSet奇怪问题 如何在.aspx页面下调用javascript脚本编写的函数? 跪求vs2008 设置编译器选项大全 使用Session传递值的问题 如何让RadioButton无刷新显示和隐藏TextBox 询问计算object对象中所存值大小问题 JavaScript得到控件属性问题,谢谢 .NET系统设置问题 链接的问题 Asp.net Form验证登录本地可以但是传到服务器上就失效的问题
dim userPassword as string = textbox2.text
你问的应该是做判断的问题吧。直接这样比较就可以。在.cs页面下
protected void Button1_Click(object sender, EventArgs e)
{
if(TextBox1.Text== "数据库里的账号"&&TextBox2.Text== "数据库里的密码")
{
Session["login"]="True"//登陆标记
Response.Redirect("登陆成功页面!");
}
}
需要验证的页面加
if(Session["login"]!="True")
Response.Redirect("进入地址");
在
提交页面
<form action="go.aspx" method="get">
<input type="text" name="userName" id="textfield" />
<input type="text" name="userPsw" id="textfield2" />
<input type="submit" name="button" id="button" value="提交" />
</form>go.aspx页面中接收值
string userName=Request.Form["userName"].ToString();
string userPsw=Request.Form["userPsw"].ToString();
if (AdminManager.CheckLogin(m))
{
string strRedirect = Request["ReturnUrl"];
System.Web.Security.FormsAuthentication.SetAuthCookie("AdminUser", true);
if (strRedirect == null)
Response.Redirect("~/Admin/Index.aspx");
Response.Redirect(strRedirect);
}
else
{
Message.ShowMessage(this,"用户名或密码错误!");
}根目录下Web.Config中
<authentication mode="Forms">
<forms name="AdminUser" loginUrl="~/Admin/Login.aspx"></forms>
</authentication>admin文件夹目录下Web.Config中
<system.web>
<authorization>
<deny users="?"/>
<allow users="AdminUser"/>
</authorization>
</system.web>
不过 转到~/Admin/Login.aspx页的时候
页面的样式都不起作用了
不知道为啥
你要知道的:Request,Response,Session,
asp.net 中的from认证个人觉得是有点麻烦了,
说白了form认证就是通过发送页面的<from>子元素要有name属性
接受页面通过Request.From[]取值,判断Session[]的过程。asp.net 中的认证机制,就是在web.config需要配置的,只不过对传统认证进行了包装的。
希望对你帮助
<forms name="forms" loginUrl="Login.aspx" protection="All" timeout="180" />
</authentication>
<authorization>
<deny users="?"/>
<allow users ="*"/>
</authorization>
----------
登录string username=txtname.Text.trim();
string password=txtpassword.Text.trim();
if(username=="aaaa" && password=="bbbbbb")
{
FormsAuthentication.RedirectFromLoginPage(username, false);
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "AlertMessage", "<script language=javascript>alert('用户名或密码错误!')</script>");
}}
http://www.cnblogs.com/luomingchao/articles/474674.html
先说下配置
<system.web>
<authentication mode="Forms">
<forms defaultUrl="admin/default.aspx" loginUrl="login.aspx" name="test" path="/" protection="All" timeout="30">
<credentials passwordFormat="MD5">
<user name="" password=""/>
</credentials>
</forms>
</authentication>指定登录后的页面为 admin/default.aspx,如果直接在地址栏中输入admin/default.aspx会直接转到login.aspx.
接下来,你还要配置admin/default.aspx页面不允许匿名访问.我的做法是指定admin目录下的所有页面,都不允许匿名用户访问.这个配置如果你熟悉的话,可以直接在web.config中修改,如果不允许的话,可以启动 vs中的项目中的asp.net配置程序,来帮助你来配置.如果你的应用比较简单,就是说用户是依靠你来分配的,那么可以简单的新增user节点,以建立一些用户群.在验证用户身份时,可以这样
if(System.Web.Security.FormsAuthentication.Authenticate(Textbox1.Text,Textbox2.Text))
{
// 做登录成功的操作
}这样在admin/default.aspx中,就可以使用Page.User.Identity.Name 来获取登录的用户名了.以上,只是Form验证中的一种.还有一种是配合数据库操作.
还有一种是结合用户和角色的(不是指Membership API)
当然也可以将authentication整个节点,建立在另一个web.config中,再以其它方式加载进来,这样的话,application是不会重启的,你也可以用程序来新增用户.
通过 <authentication> 节可以配置 ASP.NET 使用的
安全身份验证模式,
以标识传入的用户。
-->
<authorization>
<allow users="*"/>
</authorization>
<authentication mode="Forms">
<forms loginUrl="~/Logon.aspx" protection="All" timeout="30" name=".ASPXAUTH" path="/" requireSSL="false" slidingExpiration="true" cookieless="UseDeviceProfile" enableCrossAppRedirects="false"/>
</authentication>
<!--
如果在执行请求的过程中出现未处理的错误,
则通过 <customErrors> 节可以配置相应的处理步骤。具体说来,
开发人员通过该节可以配置
要显示的 html 错误页
以代替错误堆栈跟踪。 <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
</system.web>
<location path="admin"><!--这里是要登录才能操作的页面文件夹名字-->
<system.web>
<authorization>
<deny users="?"/>
<allow users="*"/>
</authorization>
</system.web>
</location>
</configuration>
//“登录”按钮事件
protected void btn_click()
{
if(Login(strUserID, strUserPassword))
{
if (Request.QueryString["ReturnUrl"] != null)
{
FormsAuthentication.RedirectFromLoginPage(username, false);
} else
{
FormsAuthentication.SetAuthCookie(username, false);
Response.Redirect("admin/Default.aspx", false);
}
}
else
Response.write("登录失败");
}protected bool Login(string userid, string password)
{
bool islogin = false;
//此处检查登录
return islogin;
}
用string name=Page.User.Identity.Name
给你参考下吧 Forms验证,多角色,多登录页
这个是webconfig
<authentication mode="Forms">
<forms name=".Member" loginUrl="Manage/Login.aspx" protection="All" timeout="20"/>
</authentication>
<!--
如果在执行请求的过程中出现未处理的错误,
则通过 <customErrors> 节可以配置相应的处理步骤。具体说来,
开发人员通过该节可以配置
要显示的 html 错误页
以代替错误堆栈跟踪。
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
<customErrors mode="Off" defaultRedirect="Error.aspx">
</customErrors>
</system.web>
<location path="Manage">
<system.web>
<authorization>
<deny users="?"/>
<allow users="*"/>
</authorization>
</system.web>
</location>
这个是对我的管理员登陆的一个Form验证
如果没有登陆的话
就不能够访问管理后台(Manage文件夹下面)
就这样就OK啦!