从asp.net前端的cookie中提取详细信息
我有一个身份验证cookie,我想知道是否可以从代码的asp.net部分(即HTML部分)的cookie中提取数据。我可以使用下面的代码在后端将其提取出来从asp.net前端的cookie中提取详细信息,asp.net,asp.net-mvc,Asp.net,Asp.net Mvc,我有一个身份验证cookie,我想知道是否可以从代码的asp.net部分(即HTML部分)的cookie中提取数据。我可以使用下面的代码在后端将其提取出来 IPrincipal p = HttpContext.Current.User; // p.Identity.Name : this is what we will use to call the stored procedure to get the data and populate it
IPrincipal p = HttpContext.Current.User;
// p.Identity.Name : this is what we will use to call the stored procedure to get the data and populate it
string userid = p.Identity.Name;
Response.Write("Welcome " +
p.Identity.Name);
var dbcontext = new PrepLicensingSolution2010.DAL.LicensingEntities1();
if (userid != null)
{
var user = dbcontext.commissions_proc(userid);
}
但这能在前端完成吗
谢谢你
<asp:Label ID="welcome" runat="server" Text='<%= String.Format("Welcome {0}", HttpContext.Current.User.Identity.Name) %>'
取决于身份验证cookie的设置方式的
。如果使用HTTPOnly,则javascript或(如果浏览器是安全的)客户端无法访问它
要访问Javascript中的cookie,只需使用
var mycokierarray=document.cookie.split(“;”)代码>
并在数组中循环查找要查找的cookie
更多信息请点击此处:您正在寻找Javascript代码吗?乍一看,这是一个非常奇怪的任务(我是关于cookies的用法)。看起来你想人为地解决你的问题。你为什么不想用饼干?请解释一下,问题的根源是什么。让我们根据您想要实现的场景(我希望应该有可能实现)。