表单身份验证在升级到.NET 4后失败

时间:2013-12-12 04:12:22

标签: asp.net forms-authentication asp.net-4.0

我有一个旧的.NET 3.5 WebForms应用程序,我试图通过升级到.NET 4来拖延到这十年。但是,在升级过程中,在身份验证过程中似乎已经出现了一些问题。

我的文件夹布局如下

/Login.aspx
/Home.aspx
/Content/Default.aspx
/Content/Stuff.aspx

在我的web.config中,我按如下方式配置了身份验证和授权:

<authentication mode="Forms">
    <forms loginUrl="Login.aspx" requireSSL="true" name="MyCookie" path="/" cookieless="UseCookies" />
</authentication>
<authorization>
    <deny users="?" />
</authorization>

然后添加

<location path="Login.aspx">
    <system.web>
        <authorization>
            <allow users="*" />
        </authorization>
    </system.web>
</location>

,意图是未经身份验证的用户应该只能访问Login.aspx页面。

当我尝试访问该应用程序时,我会被定向到登录页面;然后,我可以输入我的凭据,表单身份验证执行其功能,并且我已通过身份验证。但是,当应用程序将我重定向到Home.aspx时,它会立即将我重定向回Login.aspx?ReturnUrl=%2fHome.aspx,因此它显然认为我无法访问。

在我的global.asax中,我为Application_AuthenticateRequestApplication_PostAuthenticateRequest添加了空事件处理程序,并在它们上设置了断点。点击Application_AuthenticateRequest后,Context.User.IdentityFormsIdentity段,Context.User.Identity.IsAuthenticated = true;但当Application_PostAuthenticateRequestGenericIdentity个实例和Context.User.Identity.IsAuthenticated = false

无论是使用IE,Firefox还是Chrome,都会发生这种情况。为什么我的用户会从有效的FormsIdentity实例变为AuthenticateRequest和PostAuthenticateRequest之间无用的GenericIdentity实例?

1 个答案:

答案 0 :(得分:0)

看到这个问题。接受的答案是不正确的,但是下面的答案是所有的选票都是。

Upgrading to ASP.NET 4.5/MVC 4 forms authentication fails

相关问题