成功登录后,Asp.Net Forms身份验证再次浏览到登录页面

时间:2009-12-18 19:05:29

标签: asp.net asp.net-membership asp.net-2.0

我的表单身份验证系统正常运行。

我发现了一个奇怪的行为,成功登录后;如果我从默认页面浏览到登录页面,我被要求再次登录。

我假设它应该将我重定向到默认页面,因为我已经过身份验证。

这是我使用的Web.config元素:

<authentication mode="Forms">
 <forms loginUrl="login.aspx" defaultUrl="default.aspx" />            
</authentication>
<authorization> 
 <deny users="?"/>
</authorization>

2 个答案:

答案 0 :(得分:3)

这是正常行为。登录页面是常规的ASP.NET webform。它将显示其中的任何内容。

您可以将代码添加到登录页面的Form_Load事件中,以检查用户是否已经过身份验证。然后,您可以通过调用FormsAuthentication.RedirectFromLoginPage方法将它们重定向到默认值,如果这就是您所追求的。

答案 1 :(得分:0)

当用户使用Forms Authentication对网站进行身份验证时,服务器会创建一个cookie。 cookie的值是加密的表单身份验证票证。在每次向应用程序发出请求时,cookie都会传递给服务器,FormsAuthenticationModule类会解密cookie值并确定用户是否有效。 我认为你的项目web.config中有标记。删除它

...
<modules>
    <remove name="FormsAuthentication" />
</modules>
....

如果没有,请检查machine.config,它必须具有以下标记:

<httpModule>
    …other modules…
    <add name="FormsAuthentication"
        type="System.Web.Security.FormsAuthenticationModule" />
    …other modules…
</httpModule>