竟然遇到取FormAuthentication的值取不出来的情况

在开发中,竟然遇到取FormAuthentication的值取不出来的情况,忘了以前是怎么理解这个问题的了,为了避免问题,先放上来,容后再描述。

 出现问题的原因是当在自定义的HttpModule类中取用户的信息时,竟然什么都取不出来,以前好像解决过这个问题,但是这次竟然花了3个小时才搞懂,看来确实是老了!!

 解决方法是由于FormAuthentication实际上是由FormsAuthenticationModule实现的,所以在Web.config中重新声明这些个Module,问题就解决了.(并且一定要在你想用的Module的前面)

 <remove name="FormsAuthenticationModule" />
   <add name="FormsAuthenticationModule" type="System.Web.Security.FormsAuthenticationModule" />
   <remove name="UrlAuthorization" />
   <add name="UrlAuthorization" type="System.Web.Security.UrlAuthorizationModule" />
   <remove name="DefaultAuthentication" />
   <add name="DefaultAuthentication" type="System.Web.Security.DefaultAuthenticationModule" />

具体的原理也没搞懂,厄~~

原文地址:https://www.cnblogs.com/csharpsharper/p/1336056.html