Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在响应ASP.NET_SessionId中附加HttpContext.Current.User.Identity.Name_C#_Asp.net - Fatal编程技术网

C# 如何在响应ASP.NET_SessionId中附加HttpContext.Current.User.Identity.Name

C# 如何在响应ASP.NET_SessionId中附加HttpContext.Current.User.Identity.Name,c#,asp.net,C#,Asp.net,为了防止会话劫持,我需要将HttpContext.Current.User.Identity.Name附加到响应ASP.NET_SessionId中,我使用IHttpModule加密响应cookie(参考:) HttpContext.Current.User为空 请告诉我哪里做错了 global.asax ` 你用什么来保证安全,Forms auth?检查值时是否已对用户进行身份验证我使用的是Form auth。检查global.asax文件中的用户身份验证(Application_Authen

为了防止会话劫持,我需要将HttpContext.Current.User.Identity.Name附加到响应ASP.NET_SessionId中,我使用IHttpModule加密响应cookie(参考:)

HttpContext.Current.User为空

请告诉我哪里做错了

global.asax `


你用什么来保证安全,Forms auth?检查值时是否已对用户进行身份验证我使用的是Form auth。检查global.asax文件中的用户身份验证(Application_AuthenticateRequest)添加global.asax中的代码,这样做将有助于回答问题。有人能帮我吗?如果您担心会话劫持,您应该使用SSL
 if (HttpContext.Current.User != null)
{
if (HttpContext.Current.User.Identity.IsAuthenticated)
{
if (HttpContext.Current.User.Identity is FormsIdentity)
{
FormsIdentity id =(FormsIdentity)HttpContext.Current.User.Identity;
FormsAuthenticationTicket ticket = id.Ticket;
string userData = ticket.UserData;
string[] roles = userData.Split(',');
HttpContext.Current.User = new GenericPrincipal(id, roles);

string str = Request.Cookies["ASP.Net_SessionId"].Value;
}
}
}