已经配了2个应用,都花了不少时间,除第一次是上手的过程可以理解,第二次的问题主要是记性太差,才半年的时间就有很多要点都漏掉了,因此开博记录下自己的思路,以免事不过三。
--------------------------------------web.config设置
<!-- 单点认证需要 -->
<authentication mode="Forms">
<forms loginUrl="Login.aspx" name=".abc" domain=".***.com.cn" protection="All" path="/" timeout="1440" slidingExpiration="false"/>
</authentication>
<authorization>
<allow users="*" />
</authorization>
<machineKey validationKey="3505A10867B21A9BD7EBE80CBD00E005D1367D5C389C167C"
decryptionKey="1DBA63BA352BBBDCCAFBA6A60D7BC1D1258F77A2BB0F4E82"
validation="SHA1" decryption="3DES"/>
name=".abc" domain=".***.com.cn" 配置要点,确保.abc作为Cookie出现在domain中,可以通过火狐的cookie管理器看到。
machineKey 咨询GOOGLE
--------------------------------------后台代码,有时间验证是否可在JS中实现如下键值的存储
public static string ID
{
get
{
string Result = string.Empty;
if (HttpContext.Current.Request.Cookies["ID"] != null)
{
Result = HttpContext.Current.Request.Cookies["ID"].Value;
}
return Result;
}
set
{
HttpContext.Current.Response.Cookies["ID"].Value = value;
HttpContext.Current.Response.Cookies["ID"].Domain = ".***.com.cn";
}
}
public static void ClearCookie()
{
//清空所有Cookie
int count = HttpContext.Current.Request.Cookies.Count;
for (int i = 0; i < count; i++)
{
HttpCookie cookie = HttpContext.Current.Request.Cookies[i];
cookie.Domain = Domain;
cookie.Expires = DateTime.Now.AddHours(-24); //关键是这一句
HttpContext.Current.Response.Cookies.Add(cookie);
}
}