set .net principle
var ticket = new FormsAuthenticationTicket(1, username, DateTime.Now, DateTime.Now.AddMinutes(FormsAuthentication.Timeout.Minutes), true, JsonConvert.SerializeObject(userinfo), FormsAuthentication.FormsCookiePath);
HttpContext.Current.User = new GenericPrincipal(new FormsIdentity(ticket), null);
var hash = FormsAuthentication.Encrypt(ticket);
CookieHelper.SetCookie(FormsAuthentication.FormsCookieName, hash, FormsAuthentication.FormsCookiePath, DateTime.Now.AddMinutes(FormsAuthentication.Timeout.Minutes), true, FormsAuthentication.RequireSSL);
using System;
using System.Web.Mvc;
using System.Web.Routing;
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = true)]
public class MyAuthorizeAttribute : AuthorizeAttribute
{
protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
{
if (!filterContext.HttpContext.Request.IsAuthenticated)
{
filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { controller = "Login", action = "Login" }));
}
else
{
base.HandleUnauthorizedRequest(filterContext);
}
}
}
filterContext.Result = new RedirectToRouteResult(
new RouteValueDictionary(
new
{
controller = "Login",
action = "Login",
returnUrl = filterContext.HttpContext.Request.Url.GetComponents(UriComponents.PathAndQuery, UriFormat.SafeUnescaped)
}));
set .net principle的更多相关文章
- Atitit.软件开发的几大规则,法则,与原则Principle v3
Atitit.软件开发的几大规则,法则,与原则Principle v31.1. 修改历史22. 设计模式六大原则22.1. 设计模式六大原则(1):单一职责原则22.2. 设计模式六大原则(2):里 ...
- C#设计模式系列:开闭原则(Open Close Principle)
1.开闭原则简介 开闭原则对扩展开放,对修改关闭,开闭原则是面向对象设计中可复用设计的基石. 2.开闭原则的实现 实现开闭原则的关键就在于抽象,把系统的所有可能的行为抽象成一个抽象底层,这个抽象底层规 ...
- 开放封闭原则(Open Closed Principle)
在面向对象的设计中有很多流行的思想,比如说 "所有的成员变量都应该设置为私有(Private)","要避免使用全局变量(Global Variables)",& ...
- 最少知识原则(Least Knowledge Principle)
最少知识原则(Least Knowledge Principle),或者称迪米特法则(Law of Demeter),是一种面向对象程序设计的指导原则,它描述了一种保持代码松耦合的策略.其可简单的归纳 ...
- 接口分离原则(Interface Segregation Principle)
接口分离原则(Interface Segregation Principle)用于处理胖接口(fat interface)所带来的问题.如果类的接口定义暴露了过多的行为,则说明这个类的接口定义内聚程度 ...
- 依赖倒置原则(Dependency Inversion Principle)
很多软件工程师都多少在处理 "Bad Design"时有一些痛苦的经历.如果发现这些 "Bad Design" 的始作俑者就是我们自己时,那感觉就更糟糕了.那么 ...
- 里氏替换原则(Liskov Substitution Principle)
开放封闭原则(Open Closed Principle)是构建可维护性和可重用性代码的基础.它强调设计良好的代码可以不通过修改而扩展,新的功能通过添加新的代码来实现,而不需要更改已有的可工作的代码. ...
- 单一职责原则(Single Responsibility Principle)
单一职责原则(SRP:The Single Responsibility Principle) 一个类应该有且只有一个变化的原因. There should never be more than on ...
- [Design Patterns] 2. Design principle
Single Responsibility Principle 类的设计趋向于:Use Case Diagram --> (derived) --> Detail Open-Closed ...
- drawer principle in Combinatorics
Problem 1: Given an array of real number with length (n2 + 1) A: a1, a2, ... , an2+1. Prove that th ...
随机推荐
- LinqToExcel使用简介一
最近才看到原来也可以用Linq来访问Excel,功能还挺强大的.要使用这个功能,首先得下载一个LinqToExcel的相关文件,然后就可以调用相关的方法. 使用前面介 ...
- Mootools 学习随笔
简单的介绍下Mootools: MooTools是一个简洁,模块化,面向对象的开源JavaScript web应用框架.在处理js.css.html时候,为web开发者提供了一个跨浏览器的js解决方案 ...
- YAGNI 声明
1.YAGNI介绍 YAGNI 全名是 You aren't Going to Need It,在你设计草案的初稿中,应该努力使用最简单可以工作的事物,直至程序的某个方面要求你添加额外的特性. 2.思 ...
- 自动化测试(一)-get和post的简单应用
今天主要介绍两种测试的接口post和get: get和post是http的两种基本请求方式,区别在于get把参数包含在url中传递:给而post把参数以json或键值对的方式利用工具传递. get的传 ...
- Django数据模型--表关系(一对多)
一.一对一关系 使用方法:models.ForeignKey(要关联的模型) 举例说明:年级.教师和学生 from django.db import models class Grade(models ...
- 监控memcache服务
监控memcache服务是否正常,模拟用户(web客户端)检测. 使用nc命令加上set/get来模拟检测,以及监控响应时间及命中率. #!/bin/bash #################### ...
- LeetCode - 1. Two Sum(8ms)
Given an array of integers, return indices of the two numbers such that they add up to a specific ta ...
- centos7.4内核从3.10升级到4.14详细步骤
由于我们的docker学习中的Overlay需要内核版本在3.12+,所以在安装完centos7.4之后要进行内核升级,下面是升级步骤:1.导入keyrpm --import https://www. ...
- 在Android Studio中创建(或添加)第一个Hello World应用程序
下面我们将使用Android Studio创建第一个简单的Hello World应用程序. 1.打开Android Studio,加载画面如下图所示: 2.选择”Start a new Andro ...
- uva 11526 H(n) (数论)
转载自 http://blog.csdn.net/synapse7/article/details/12873437 这道题我自己做的时候没有想到好的优化方法,提交的时候借鉴这篇文章的内容,转载如下: ...