在asp.net中读取mvc的cookie [英] cookies reading in mvc in asp.net
本文介绍了在asp.net中读取mvc的cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好
这个代码我可以读取cookies
hello
by this code i can read cookies
HttpCookie authCookie = Request.Cookies["match.FormsAuthentication"];
if (authCookie != null)
{
Response.Write(authCookie.Value);
}
但如果在web.config中找到此代码,我无法通过此代码阅读
but i can not read it by this code if this code found in web.config
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="2880"
protection="All"
name="ExampleSite.FormsAuthentication"
path="/"
requireSSL="false"
slidingExpiration="true"
defaultUrl="index.aspx"
cookieless="UseDeviceProfile"
enableCrossAppRedirects="false"
/>
</authentication>
推荐答案
您可以使用java脚本阅读cookies ...尝试使用fallowing code.Hope它将解决您的问题。
You can use java script to read cookies... Try with fallowing code.Hope it will solve your problem.
<script type="text/javascript">
function GetUserCookie() {
document.getElementById('lblFieldName1').innerHTML = getCookie("UserName").toUpperCase();
document.getElementById('lblFieldName2').innerHTML = getCookie("branch_name").toLowerCase();
}
function getCookie(cookiename) {
// Get name followed by anything except a semicolon
var cookiestring = RegExp("" + cookiename + "[^;]+").exec(document.cookie);
// Return everything after the equal sign
return unescape(!!cookiestring ? cookiestring.toString().replace(/^[^=]+./, "") : "");
}
</script>
这篇关于在asp.net中读取mvc的cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文