为什么 HttpContext.User.Identity.Name 不定期为空?
context.User.Identity.Name 很少为空。我认为这是不可能的,因为我在使用用户之前检查用户是否经过身份验证,如果没有,则重定向到登录页面。 99% 的情况下,此代码运行良好,但有时在尝试 GetMemberNumber 时会遇到问题,因为传递的值是空的。有谁知道这里会发生什么吗?
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
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">
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
重定向后代码执行不会停止。
code execution will not stop after redirect.