【问题标题】:Migrating from FormsAuthentication to Identity. FormsAuthentication.DefaultUrl从 FormsAuthentication 迁移到 Identity。 FormsAuthentication.DefaultUrl
【发布时间】:2014-10-03 22:00:26
【问题描述】:

从 FormsAuthentication 迁移到 Identity 时,我有一些代码:

return Redirect(FormsAuthentication.DefaultUrl);

在 Identity 我没有找到这个配置(我也不知道为什么它首先在 FormsAuthentication 上)我将更改为

return Redirect("~/");

此场景是否有任何身份配置,或者只是从身份中删除了该功能?

【问题讨论】:

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


    【解决方案1】:

    这在 Identity 中不存在。

    但是,当您进行身份配置时,您会在 Auth.Config.cs 中执行类似的操作

            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath = new PathString("/Account/Login"),
    
                // other stuff
             }
    

    看到LoginPath 属性集了吗?这就是现在与FormsAuthentication.DefaultUrl 工作方式相同的重定向地址,只是您没有在web.config 中指定它。

    【讨论】:

    • 只需将路径分配给公共常量并在需要的地方重用
    猜你喜欢
    • 2022-01-04
    • 2022-01-02
    • 2014-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-06
    • 2015-02-16
    • 1970-01-01
    相关资源
    最近更新 更多