故障原因:从framework4.0到framework4.5的升级过程中,原有的form认证方式发生了变化,所以不再支持User.Identity.Name原有存储模式(基于cookie),要恢复这个功能,我也是偶然间发现的。
一下五种解决方案根据具体情况供参考
1、降级处理,把你的framework降到4.0
<compilation debug="true " targetFramework=" 4.0" />
    < httpRuntime targetFramework ="4.0" />
 
2、set the Current User myself in the Global.asax:(不用降级只需加上这段代码)
 private void Application_AuthenticateRequest(Object sender, EventArgs e)
{
HttpCookie cookie = HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName];
if (cookie != null)
{
FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(cookie.Value);
HttpContext.Current.User = new System.Security.Principal.GenericPrincipal(new FormsIdentity(ticket), new string[0]);
}
}
 3、 <machineKey validationKey="12..." decryptionKey="34..." 
                validation="SHA1" decryption="AES"
                compatibilityMode="Framework20SP1" />
4、SessionAuthenticationModule

Since you're in 4.5 and since you're manually issuing the cookie and since you're already intercepting the cookie, then you're not really using the forms auth HTTP module at all. I'd remove that for now. Also, change your module to handle AuthenticateRequest. See how that works.

Then once you do get it working, I'd scrap it all in favor of claims and using the SessionAuthenticationModule which is new and built into 4.5. It is far simpler and will serialize all of your roles into a cookie for you.

http://msdn.microsoft.com/zh-cn/library/system.identitymodel.services.sessionauthenticationmodule(v=vs.110).aspx

5

Make sure that the machineKey compatibility mode is the same between all applications:
<machineKey compatibilityMode="Framework20SP1" />

(The above is the default for 2.0 / 4.0 applications but is not the default for 4.5 applications, so it will have to be set explictly in the 4.5 application.)

HttpContext.Current.User is null after installing .NET Framework 4.5的更多相关文章

  1. System.Web.HttpContext.Current.Session为NULL解决方法

    http://www.cnblogs.com/tianguook/archive/2010/09/27/1836988.html 自定义 HTTP 处理程序,从IHttpHandler继承,在写Sys ...

  2. 为什么获取的System.Web.HttpContext.Current值为null,HttpContext对象为null时如何获取程序(站点)的根目录

    ASP.NET提供了静态属性System.Web.HttpContext.Current,因此获取HttpContext对象就非常方便了.也正是因为这个原因,所以我们经常能见到直接访问System.W ...

  3. System.Web.HttpContext.Current.Session为NULL值的问题?

    自定义 HTTP 处理程序,从IHttpHandler继承,在写System.Web.HttpContext.Current.Session["Value"]的时 候,没有问题,但 ...

  4. 异步 HttpContext.Current 为空null 另一种解决方法

    1.场景 在导入通讯录过程中,把导入的失败.成功的号码数进行统计,然后保存到session中,客户端通过轮询显示状态. 在实现过程中,使用的async调用方法,出现HttpContext.Curren ...

  5. 异步任务,HttpContext.Current为null解决办法

    最近在开发一个后台管理系统项目,为了提高登录的速度,就把记录登录日志放到一个异步任务里面. Action taskAction = () => { SaveLog(); }; Task task ...

  6. HttpContext.Current 的缺陷

    了解ASP.NET的开发人员都知道它有个非常强大的对象 HttpContext,而且为了方便,ASP.NET还为它提供了一个静态属性HttpContext.Current来访问它,今天的博客打算就从H ...

  7. HttpContext.Current.Server.MapPath("/") 未将对象设置到对象的实例异常。

    多线程中的System.Web.HttpContext.Current.Server.MapPath("/") 多线程中Server.MapPath会失效... 网上找到几种解决方 ...

  8. HttpContext.Current并非无处不在

    阅读目录 开始 无处不在的HttpContext HttpContext.Current到底保存在哪里? HttpContext并非无处不在! 如何获取文件绝对路径? 异步调用中如何访问HttpCon ...

  9. Cache及(HttpRuntime.Cache与HttpContext.Current.Cache)

    本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/avon520/archive/2009/11/25/4872704.aspx .NET中Cache有两种调用方式:Ht ...

随机推荐

  1. Android广播

    Android中的广播主要分为两类,标准广播和有序广播   标准广播: 一种完全异步执行的广播,在广播发出之后,所有的广播接收器几乎都会在同一时刻接收到这条广播消息,因此没有任何的先后顺序 这种广播的 ...

  2. Gulp的使用教程

  3. Get Script Path in Shell

    #!/usr/bin/bashdir_old=$(pwd)absolute_script_path=$(cd $(dirname $0) && pwd)relative_script_ ...

  4. CF #296 (Div. 1) A. Glass Carving 线段树

    A. Glass Carving time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  5. Emmet 使用说明。

    Emmet for Sublime Text Official Emmet plugin for Sublime Text. How to install Available actions Exte ...

  6. 用PowerMock mock final类

    mock final类相对简单,直接贴代码 被测方法: public class FinalEmployeeService { public void insertEmployee(Employee ...

  7. HttpRequestUtil

    package com.didichuxing.tempdirreader; import com.alibaba.fastjson.JSONObject; import java.io.Unsupp ...

  8. 测试数学公式latex

    \( J_\alpha(x) = \sum\limits_{m=0}^\infty \frac{(-1)^m}{m! + 1)}{\left({\frac{x}{2}}\right)}^{2 m + ...

  9. sql返回两个日期之间的日期_函数实现

    -- Description:返回两段日期之间的所有日期    <Description,,>-- ============================================ ...

  10. greendao 3.1.0在android studio中配置

    1 项目根build.gradle classpath 'org.greenrobot:greendao-gradle-plugin:3.1.0' 2 app中build.gradle apply p ...