简体   繁体   中英

Why is HttpContext.User.Identity.Name irregularly empty?

context.User.Identity.Name will very rarely be empty. I did not think this was possible since I'm checking if the user is authenticated before using it, and redirecting to the login page if they are not. 99% of the time this code runs fine, but I'm sometimes having issues when trying to GetMemberNumber, as the value that is being passed is a empty. Does anyone have any ideas what could be going on here?

FromRA.ashx.cs

using System;
using System.Threading.Tasks;
using System.Web;
using System.Web.Configuration;
using System.Web.Security;
using Helpers;

namespace Transfer
{
   public class FromRA : HttpTaskAsyncHandler
   {
       public override async Task ProcessRequestAsync(HttpContext context)
       {
           if (!context.User.Identity.IsAuthenticated)
               FormsAuthentication.RedirectToLoginPage();

           var memberNumber = MembershipUtils.GetMemberNumber(context.User.Identity.Name);

           var remediationServiceProviderResult = await Global.RestrictedAccess
               .GetRemediationServiceProviderResult(memberNumber);

           //...irrelevant code
       }
   }
}

Web.config

<authentication mode="Forms">

code execution will not stop after redirect.

    public override async Task ProcessRequestAsync(HttpContext context)
           {
               if (!context.User.Identity.IsAuthenticated)
               {
                   FormsAuthentication.RedirectToLoginPage();
                   return;
               }
    
    
               var memberNumber = MembershipUtils.GetMemberNumber(context.User.Identity.Name);
    
               var remediationServiceProviderResult = await Global.RestrictedAccess
                   .GetRemediationServiceProviderResult(memberNumber);
    
               //...irrelevant code
           }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM