【发布时间】:2013-09-16 14:31:17
【问题描述】:
我正在尝试使用FormsAuthentication.RedirectFromLoginPage(username,true,cookiepath);
在使用FormsAuthentication.RedirectFromLoginPage 时,它会重定向到web.config 中提供的DefaultUrl。
web.config 中的身份验证部分:
<authentication mode="Forms">
<forms name=".ASPXADMINAUTH"
loginUrl="/Default.aspx"
defaultUrl="homepage.aspx"
protection="All"
timeout="30" path="/admin" slidingExpiration="true" enableCrossAppRedirects="false" cookieless="UseCookies" domain="localhost" ticketCompatibilityMode="Framework20" ></forms>
</authentication>
在 httpModules 部分:
<add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule" />
页面正在从登录页面重定向到“homepage.aspx”,但它没有设置身份验证 cookie。
在我的Response header中,Set-Cookie包含Authentication cookie,但在homepage.aspx页面中没有设置。
所以 LoginStaus 和 LoginName 控件不起作用。
【问题讨论】:
-
听起来您正在通过与设置 cookie 不同的域名访问您的网站。
-
@KlausByskovPedersen 感谢您的回复。在我的代码中,我将域用作“localhost:51370”,并且我还通过删除域属性进行了检查。但是没有用。
-
您的所有页面都位于
/admin下吗?因为如果不是,您应该将path属性更改为/。 -
域名有什么用..? /admin 和 /.. 有区别吗?
-
如果您为
domain=localhost和path=/admin设置cookie,您的浏览器只会在访问该域上的资源并使用正确路径(例如http://localhost/admin/somepage.aspx。如果您访问http://localhost/Default.aspx,它不会将cookie发送到服务器,因为路径不匹配。域也是如此。如果您为localhost设置了cookie,但后来通过mydevserver等别名访问服务器,浏览器也不会发送cookie。
标签: c# asp.net cookies asp.net-membership forms-authentication