在Global.acax中,添加下面方法

  1. //设置session可用
  2. public override void Init()
  3. {
  4. PostAuthenticateRequest += MvcApplication_PostAuthenticateRequest;
  5. base.Init();
  6. }
  7.  
  8. void MvcApplication_PostAuthenticateRequest(object sender, EventArgs e)
  9. {
  10. HttpContext.Current.SetSessionStateBehavior(
  11. SessionStateBehavior.Required);
  12. }

可以关注本人的公众号,多年经验的原创文章共享给大家。

  1.  

  1.  

C# WebApi 中设置Session可用的更多相关文章

  1. .net webapi 中使用session是出错 HttpContext.Current.Session==null

    最近在写.net webapi时发现 HttpContext.Current.Session==null  ,导致报错,后来查资料发现webapi中使用session时首先需要开启session功能, ...

  2. C# asp.net IIS 在web.config和IIS中设置Session过期时间

    有时候在web.config设置sessionState 或者类文件里设置Session.Timeout,在IIS里访问时每次都是达不到时间就超时,原因是因为在IIS中设置了Session的超时时间, ...

  3. Java进阶(十五)Java中设置session的详细解释

    Java中设置session的详细解释 简单通俗的讲session就是象一个临时的容器,用来存放临时的东西.从你登陆开始就保存在session里,当然你可以自己设置它的有效时间和页面,举个简单的例子: ...

  4. asp中设置session过期时间方法总结

    http://www.jb51.net/article/31217.htm asp中设置session过期时间方法总结 作者: 字体:[增加 减小] 类型:转载   asp中默认session过期时间 ...

  5. .NET WebAPI中使用Session使用

    问题及其解决方案: 今天做项目的时候因为需要编写一个短信验证码的接口我需要在我的后台.net webapi中存入我随机生成的短信验证码方便与前端传递过来的数据对比,所以决定使用session做缓存.但 ...

  6. WebApi 中使用 Session

    1. 在 Global.asax.cs 文件中加入session支持 protected void Application_Start() { AreaRegistration.RegisterAll ...

  7. java 中设置session失效时间

    程序中session都有一个默认的过期时间,其中tomcat中的默认时间为30分钟,根据需要我们可以去手动设置session的过期时间,以下是设置session的过期时间的三个方法:1.在tomcat ...

  8. Java中设置Session过期时间(Spring Boot)

    1.Spring Boot: server.session.cookie.comment = #注释会话cookie. server.session.cookie.domain = #会话cookie ...

  9. PHP中设置session过期的时间

    如何严格限制session在30分钟后过期!1.设置客户端cookie的lifetime为30分钟:2.设置session的最大存活周期也为30分钟:3.为每个session值加入时间戳,然后在程序调 ...

随机推荐

  1. A - Class Statistics

    A - Class Statistics Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Subm ...

  2. 10.Date对象

    Date()对象 Date对象用于处理日期和时间. Math对象 ◆Math.ceil()   天花板函数    向上取整 ★如果是整数,取整之后是这个数本身 ★如果是小数,对数进行向上舍入. ◆Ma ...

  3. php开发工具,zendstudio13使用方法补丁

    官网原版下载http://downloads.zend.com/studio ... win32.win32.x86.exe 破解补丁:链接:http://pan.baidu.com/s/1gdi4U ...

  4. CentOS7下gitlab的搭建

    gitlab的搭建 安装基础包 yum -y install curl policycoreutils openssh-server openssh-clients 启动sshd systemctl ...

  5. [LintCode] 拓扑排序

    http://www.lintcode.com/zh-cn/problem/topological-sorting/# 给定一个有向图,图节点的拓扑排序被定义为: 对于每条有向边A--> B,则 ...

  6. .net core 与ELK(2)安装Elasticsearch可视化工具

    elasticsearch-head是els的界面插件,地址https://github.com/mobz/elasticsearch-head 1.进入github并下载 wget https:// ...

  7. ASP.Net MVC OA项目笔记<三>

    1.1.1 业务层和数据层之间加一个数据会话层,封装所有数据操作类实例的创建(工厂类) 工厂类是负责对象的创建 作用:将BLL和DAL解耦了,提供一个数据访问的统一访问点 数据会话层DBSession ...

  8. Lerning Entity Framework 6 ------ Introduction to TPT

    Sometimes, you've created a table for example named Person. Just then, you want to add some extra in ...

  9. Spring Boot中使用@Async实现异步调用

    在Spring Boot中,我们只需要通过使用@Async注解就能简单的将原来的同步函数变为异步函数,为了让@Async注解能够生效,还需要在Spring Boot的主程序中配置@EnableAsyn ...

  10. 【多线程】:Synchronized和ReentrantLock的对比

    相同点: 两者都是可重入锁,同一个线程每进入一次,锁的计数器都自增1,等到锁的计数器下降为0时才能释放锁. 底层实现对比: Synchronized是依赖于JVM实现的,而ReentrantLock是 ...