asp net mvc 4 中security.formsauthentication验证用户状态(匿名已登录)

asp net mvc 4 中security.formsauthentication验证用户状态(匿名已登录)

ID:26594194

大小:363.26 KB

页数:12页

时间:2018-11-27

asp net mvc 4 中security.formsauthentication验证用户状态(匿名已登录)_第1页
asp net mvc 4 中security.formsauthentication验证用户状态(匿名已登录)_第2页
asp net mvc 4 中security.formsauthentication验证用户状态(匿名已登录)_第3页
asp net mvc 4 中security.formsauthentication验证用户状态(匿名已登录)_第4页
asp net mvc 4 中security.formsauthentication验证用户状态(匿名已登录)_第5页
资源描述:

《asp net mvc 4 中security.formsauthentication验证用户状态(匿名已登录)》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库

1、ASP.netMVC4中Security.FormsAuthentication验证用户的状态(匿名

2、已登录)专题图编号:ylbtechASPnetMvc100010013Mvc4Security1,功能描述   ASP.netMVC4 下利用System.Web.Security.FormsAuthentication类,验证用户的状态(匿名

3、已登录)以项目为例:在视图和和区域里的视图,分别都列举俩个页面(允许匿名和不允许匿名)。 2,技术与环境  ASP.netMVC4 下System.Web.Security.FormsAuthentication类,验证用户的状态(匿名

4、

5、已登录)3,解决方案资源管理器 4,功能截图 4.1,匿名状态下()  4.1.1  /Home/Index  网站首页   4.1.2  /Account/Login  登录   4.1.3  只要是匿名用户,单击加“[NM]”修饰的地址,都会跳转到/Accout/Login页面  4.2,已登录状态下  4.2.1  /Accout/Index  用户中心 5,代码分析 5.1,  /web.config  设置重定向登录页面

6、5.2,  /Controllers/AccountController.cs 账户管理控制器  ylb_tip:1, 加“[Authorize]”修饰的方法拒绝匿名。                            ylb_tip:2, 提示如果是"HttpPost"提交,则Request["param"])则再也获取不了值。 ylb_tip:3, 在返回"ReturnUrl"的时候与以前的不同。using System.Web.Mvc; using System.Web.Security;namespace Mvc4Security.C

7、ontrollers{    public class AccountController:Controller    {        //        //GET:/Account/        [Authorize]        public ActionResultIndex()        {            return View();        }         //        // GET:/Account/Login         [HttpGet]        public ActionResultLogin()        { 

8、           //如果是跳转过来的,则返回上一页面ReturnUrl            if (!string.IsNullOrEmpty(Request["ReturnUrl"]))            {                string returnUrl=Request["ReturnUrl"];                ViewData["ReturnUrl"]=returnUrl; //如果存在返回,则存在隐藏标签中             }             //如果是登录状态,则条转到个人主页            if (S

9、ession["Username"]!=null)            {                return RedirectToAction("Index");            }            else            {                return View();            }        }         //        //Post:/Account/Login         [HttpPost]        public ActionResultLogin(string username,stri

10、ng userpass,string returnUrl)        {             if (username=="sunshine" &&userpass=="m123")            {                 //创建身份验证票证,即转换为“已登录状态”                FormsAuthentication.SetAut

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。