【发布时间】:2013-07-24 06:18:09
【问题描述】:
我用 ASP.NET 开发了网站。现在我进行身份验证。
授权由另一个 Web 服务进行。如果网络服务的答案是成功,我会创建一张票:
var ticket = new FormsAuthenticationTicket(1, param.Login, DateTime.Now, DateTime.Now.AddDays(1), false, string.Empty, FormsAuthentication.FormsCookiePath);
var encTicket = FormsAuthentication.Encrypt(ticket);
var AuthCookie = new HttpCookie(FormsAuthentication.FormsCookieName)
{
Value = encTicket,
Expires = DateTime.Now.AddDays(1)
};
Response.Cookies.Set(AuthCookie);
此代码添加了身份验证 cookie。但是如果我在前面的代码之后添加下一个字符串:
Response.Redirect("<redirect address>");
重定向后cookie消失。
为什么会这样?
此处是验证的 web.config 部分:
<authentication mode="Forms">
<forms name=".ASPXFORMSAUTH" loginUrl="~/login.ashx" />
</authentication>
【问题讨论】:
-
在 Response.Redirect() 中,您是在同一网站内引导用户还是将用户引导至外部网站?如果您直接在同一个网站中,在 Response.Redirect() 完成后是否会出现登录页面?
-
我将用户重定向到同一个站点。
标签: asp.net authentication cookies formsauthenticationticket