FormsAuthentication.RedirectFromLoginPage 登录
首先讲的这个东西是针对后台数据访问的
比如我的后台是admin文件夹.那么我除非登陆成功才可以访问里面的东西.
那么除了Session对象判断.和Cookies来判断还能用到
FormsAuthentication.RedirectFromLoginPage 登录
首先我们在网站的根目录下的
web.config配置
<authentication mode="Forms">
<forms name=".ASPXUSERDEMO" loginUrl="Login.aspx" protection="All" timeout="30"/>
</authentication>
name=".ASPXUSERDEMO"是默认的可写可不写
后面的大家参加我另外转载的一篇文章
http://www.cnblogs.com/haik/archive/2010/05/01/1725793.html
-----------------------------上面是身份验证的
-----------------下面是授权的
<authorization>
<deny users="?"/>
</authorization>
也是写在web.config配置里.
但是这个web.config我们得放到
需要做判断的文件夹下.比如我们写的admin文件夹下.
呵呵,这个东西很爽的,当用了FORM认证,如果你没有登录,不管你打开的哪页
,都会进入指定的登录页面,登录完成后,又能返回你指定的页...
我们在用的页面这样写
login.aspx中:
FormsAuthentication.RedirectFromLoginPage(userid,false);
Response.Redirect("zzz.aspx");
RedirectFromLoginPage是封装了传登录信息,必须要是 mode="Forms"才能传,Response.Redirect转页。
得这个值是Page.User.Identity.Name //得到userid的值
FormsAuthentication.RedirectFromLoginPage(userid,false); //两个参数 一个字符串 一个Cookies对象
System.Web.Security.FormsAuthentication.SetAuthCookie(this.txtname.Text,true);
Response.Redirect(“”);
这二行代码实现你在填写登录名和密码后,成功就转到你想转的页面。
System.Web.Security.FormsAuthentication.RedirectFromLoginPage(this.txtname.Text,false);
这一行代码实现你在填写登录名和密码后,成功就转到原先你想到的页面。
这后面的参数“false”说明是否永久保留cookie。True则表示永久保留,下次访问就不用输入密码了,否则断开本次链接后,下次还需要输入密码。这次参数也可以由用户选择,因为考虑到安全性,可以在用户名或密码的傍边放个checkbox,原来的语句可以为:
System.Web.Security.FormsAuthentication.RedirectFromLoginPage(this.txtname.Text,this.CheckBox.Checked);
注:cookie的登出为:
System.Web.Security.FormsAuthentication.SignOut();
---------------------
本文来自 works07 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/works07/article/details/5909866?utm_source=copy
FormsAuthentication.RedirectFromLoginPage 登录的更多相关文章
- MVC 登录后重定向回最初请求的 URL FormsAuthentication.RedirectFromLoginPage
在传统的Asp.net webForm 中如果使用 Form身份验证.登录后重定向到最初请求的页面只需使用 FormsAuthentication.RedirectFromLoginPage 但在MV ...
- asp.net 登陆验证 Form表单验证的3种方式 FormsAuthentication.SetAuthCookie;FormsAuthentication.RedirectFromLoginPage;FormsAuthenticationTicket
我们在登陆成功后,使用下面的3种方法,都是同一个目的:创建身份验证票并将其附加到 Cookie, 当我们用Forms认证方式的时候,可以使用HttpContext.Current.User.Ident ...
- 利用FormsAuthentication.RedirectFromLoginPage进行身份验证
web.config中: <authentication>节 格式: <authentication mode="Forms"> //I.Window ...
- FormsAuthentication实现登录(转)
配置项描述: <authentication mode="Forms"> <forms name=".ASPXAUTH" loginUrl=& ...
- Form身份验证
Forms身份验证Web.config<system.web><authentication mode="Forms"> <fo ...
- C#中登录验证FormsAuthentication
1:前台编写一个登录界面,这里为了简化,只有用户名和密码 代码如下: <form method="post" action="/User/CheckLogin&qu ...
- FormsAuthentication.SetAuthCookie 方法登录
FormsAuthentication.SetAuthCookie 方法,登录的原理. FormsAuthentication.SetAuthCookie 方法登录的过期时间. 登录相关阅读 asp. ...
- FormsAuthentication使用指南,实现登录
一般情况下,在我们做访问权限管理的时候,会把用户的正确登录后的基本信息保存在Session中,以后用户每次请求页面或接口数据的时候,拿到Session中存储的用户基本信息,查看比较他有没有登录和能否访 ...
- FormsAuthentication 登录兼容 IE11 保存cookie
现象:使用FormsAuthentication进行登录验证,在IE11客户端无法保存cookie 解决方法:在web.config中的forms中增加cookieless="UseCook ...
随机推荐
- 大话设计模式--中介者模式 Mediator --C++实现实例
1. 中介者模式: 用一个中介对象来封装一系列的对象交互,中介者使各对象不需要显式地相互引用,从而使其耦合松散,而且可以独立改变他们之间的交互. Mediator的出现减少了各个Colleague的耦 ...
- DBGrid1
A.ShowMessage(IntToStr(Column.Index)); B.ShowMessage(IntToStr(dbgrid1.SelectedField.Index)); .得到当前 ...
- Delphi中TList类应用
在DELPHI中指针最常见的就是和类TLIST结合起来使用.下面是一个很简单的例子,希望对这个例子的分析能让大家对使用TLIST类有一个简单的认识. 代码的功能是使用指针和Tlist来生成一个牌串,并 ...
- Python基础-处理时间模块
import datetime, time # print(time.time()) # 获取当前时间戳,从unix元年开始到现在过了多少秒# print(time.sleep(19)) # 休息几s ...
- Python 爬虫 —— 网页内容解析(lxml)
0. xpath 语法 找到所有 <img src=....> 图像的链接: xpath = './/img/@src' img_urls = html.xpath(xpath) @修饰节 ...
- perl: warning: Falling back to the standard locale ("C").
/********************************************************************************** * perl: warning: ...
- centos下安装Mysql5.7.20
0.环境 本文操作系统: CentOS 7.2.1511 x86_64MySQL 版本: 5.7.16 1.卸载系统自带的 mariadb-lib [root@centos-linux ~]# rpm ...
- Agc016_D XOR Replace
传送门 题目大意 给定两个长为$n$的序列$A,B$你可以进行若干组操作,每次操作选定一各位置$x$,令$A_x$等于$A$的异或和. 问能否通过一定操作使得$A$成为$B$,如果能,求最小操作书数. ...
- python 爬取腾讯视频评论
import urllib.request import re import urllib.error headers=('user-agent','Mozilla/5.0 (Windows NT 1 ...
- ACM学习历程—UESTC 1215 Secrete Master Plan(矩阵旋转)(2015CCPC A)
题目链接:http://acm.uestc.edu.cn/#/problem/show/1215 题目大意就是问一个2*2的矩阵能否通过旋转得到另一个. 代码: #include <iostre ...