使用Forms Authentication
using System;using System.Web;using System.Web.Security;namespace AuthTest{ public class Authentication { /// <summary> /// 设置用户登陆成功凭据(Cookie存储) /// </summary> /// <param name="UserName">用户名</param> /// <param name="PassWord">密码</param> /// <param name="Rights">权限</param> public static void SetCookie(string UserName,string PassWord,string Rights) { // //String PassWord="test"; // String UserData = UserName + "#" + PassWord+"#"+Rights; if (true) { //数据放入ticket FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, UserName, DateTime.Now, DateTime.Now.AddMinutes(60), false, UserData); //数据加密 string enyTicket = FormsAuthentication.Encrypt(ticket); HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, enyTicket); HttpContext.Current.Response.Cookies.Add(cookie); } } /// <summary> /// 判断用户是否登陆 /// </summary> /// <returns>True,Fales</returns> public static bool isLogin() { return HttpContext.Current.User.Identity.IsAuthenticated; } /// <summary> /// 注销登陆 /// </summary> public static void logOut() { FormsAuthentication.SignOut(); } /// <summary> /// 获取凭据中的用户名 /// </summary> /// <returns>用户名</returns> public static string getUserName() { if (isLogin()) { string strUserData = ((FormsIdentity)(HttpContext.Current.User.Identity)).Ticket.UserData; string[] UserData = strUserData.Split('#'); if (UserData.Length != 0) { return UserData[0].ToString(); } else { return ""; } } else { return ""; } } /// <summary> /// 获取凭据中的密码 /// </summary> /// <returns>密码</returns> public static string getPassWord() { if (isLogin()) { string strUserData = ((FormsIdentity)(HttpContext.Current.User.Identity)).Ticket.UserData; string[] UserData = strUserData.Split('#'); if (UserData.Length!=0) { return UserData[1].ToString(); } else { return ""; } } else { return ""; } } /// <summary> /// 获取凭据中的用户权限 /// </summary> /// <returns>用户权限</returns> public static string getRights() { if (isLogin()) { string strUserData = ((FormsIdentity)(HttpContext.Current.User.Identity)).Ticket.UserData; string[] UserData = strUserData.Split('#'); if (UserData.Length!=0) { return UserData[2].ToString(); } else { return ""; } } else { return ""; } } }}使用Forms Authentication的更多相关文章
- Nancy之Forms authentication的简单使用
一.前言 想必大家或多或少都听过微软推出的ASP.NET Identity技术,可以简单的认为就是一种授权的实现 很巧的是,Nancy中也有与之相类似的技术Authentication,这两者之间都用 ...
- Nancy 学习-身份认证(Forms authentication) 继续跨平台
开源 示例代码:https://github.com/linezero/NancyDemo 上篇讲解Nancy的Basic Authentication,现在来学习Nancy 的Forms身份认证. ...
- ASP.NET 4.0 forms authentication issues with IE11
As I mentioned earlier, solutions that rely on User-Agent sniffing may break, when a new browser or ...
- Forms Authentication in ASP.NET MVC 4
原文:Forms Authentication in ASP.NET MVC 4 Contents: Introduction Implement a custom membership provid ...
- Forms Authentication and Role based Authorization: A Quicker, Simpler, and Correct Approach
https://www.codeproject.com/Articles/36836/Forms-Authentication-and-Role-based-Authorization Problem ...
- An Overview of Forms Authentication (C#)
https://docs.microsoft.com/en-us/aspnet/web-forms/overview/older-versions-security/introduction/an-o ...
- .net core 共享 .Net Forms Authentication cookie
Asp.net 项目迁移到 asp.net core 项目后需要 兼容以前老的项目的登录方式. Forms Authentication cookie 登录. 从网上搜集到关于这个问题的解决思路都没有 ...
- ASP.NET Session and Forms Authentication and Session Fixation
https://peterwong.net/blog/asp-net-session-and-forms-authentication/ The title can be misleading, be ...
- Forms authentication timeout vs sessionState timeout
https://stackoverflow.com/questions/17812994/forms-authentication-timeout-vs-sessionstate-timeout Th ...
- SSRS 2016 Forms Authentication
SSRS 2016 comes with completely new report manager web interface and implementing form authenticatio ...
随机推荐
- hdu-题目1421:搬寝室
http://acm.hdu.edu.cn/showproblem.php?pid=1421 搬寝室 Time Limit: 2000/1000 MS (Java/Others) Memory ...
- Socket 传一幅图片给另一个终端
练习Socket传文件,先添加一个组件,简化socket发送和接收文件, 获取IP和端口的类 public static class AddressHelper { /// <summary&g ...
- 洛谷P3601签到题(欧拉函数)
题目背景 这是一道签到题! 建议做题之前仔细阅读数据范围! 题目描述 我们定义一个函数:qiandao(x)为小于等于x的数中与x不互质的数的个数. 这题作为签到题,给出l和r,要求求. 输入输出格式 ...
- 【bzoj5146】有趣的概率 微积分
题目描述 "可爱的妹子就像有理数一样多,但是我们知道的,你在数轴上随便取一个点取到有理数的概率总是0,"芽衣在床上自顾自的说着这句充满哲理的话,"诶,柚子,我写完概率论的 ...
- 【JavaScript&jQuery】$.ajax()
$(function(){ $('#send').click(function(){ $.ajax({ type: "GET", url: "test.json" ...
- BZOJ3573 HNOI2014米特运输
显然确定一个点的权值后整棵树权值确定.只要算出根节点的权值就能知道两种改法是否等价. 乘的话显然会炸,取log即可.map似乎会出一些问题,sort即可. #include<iostream&g ...
- BZOJ2005 能量汇集 【gcd求和】
2005: [Noi2010]能量采集 Time Limit: 10 Sec Memory Limit: 552 MB Submit: 4368 Solved: 2607 [Submit][Sta ...
- redis搭建集群并用TreeSoft管理
前言:redis作为一款高效的NOSQL数据库已经深入贯彻和落实到我们的日常开发代码中,作为缓存.时间控制.数据仓库.队列等使用方法层出不穷,简直是开写代码.居家旅行之必备良药.曾经,我们的项目都是单 ...
- 《javascript高级程序设计(第3版)》-1
javascript有下列三个不同的部分组成: ECMAScript,由ECMA-262定义,提供核心语言功能 文档对象模型(DOM),提供访问和操作网页内容的方法和接口 浏览器对象模型(BOM),提 ...
- for循环中的i++和++i
直接上代码............. #include <iostream> using namespace std; int main() { int i, k,l,p; k = 0; ...