ASP标识GetExternalLoginInfoAsync始终返回null

本文关键字:返回 null 标识 GetExternalLoginInfoAsync ASP | 更新日期: 2023-09-27 18:01:10

var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();
if (loginInfo == null)
{
     return RedirectToAction("Login");
}

loginInfo总是为空,我用fiddler检查响应,似乎网站(Steam(返回了正确的值

"response": {
        "players": [
            {
                "steamid": "76561198057961078",
                "communityvisibilitystate": 3,
                "profilestate": 1,
                "personaname": "Press '"R'" to restart™",
                "lastlogoff": 1435947642,
                "commentpermission": 2,
                "profileurl": "http://steamcommunity.com/id/warheat1990/",
                "avatar": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/59/598fa035b19342a9e0b26a8115e8ddc5da0cc900.jpg",
                "avatarmedium": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/59/598fa035b19342a9e0b26a8115e8ddc5da0cc900_medium.jpg",
                "avatarfull": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/59/598fa035b19342a9e0b26a8115e8ddc5da0cc900_full.jpg",
                "personastate": 1,
                "primaryclanid": "103582791434936111",
                "timecreated": 1327988764,
                "personastateflags": 0
            }
        ]
    }

那我为什么会变空呢?我在SO读到了很多有同样问题的人发来的帖子,但到目前为止运气不好。

任何帮助都将不胜感激。

ASP标识GetExternalLoginInfoAsync始终返回null

所以我得到null的原因是因为我在Startup.Auth.cs 中将app.UseSteamAuthentication("ABCDEFGHIJKLMNOPQRSTUVWXYZ");放在app.CreatePerOwinContext之前

public void ConfigureAuth(IAppBuilder app)
{
    app.UseSteamAuthentication("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); //if you put it here, it won't work
    // Configure the db context, user manager and signin manager to use a single instance per request
    app.CreatePerOwinContext(ApplicationDbContext.Create);
    app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
    app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);
    //rest of the code here
}

所以我把它改成:

public void ConfigureAuth(IAppBuilder app)
{
    // Configure the db context, user manager and signin manager to use a single instance per request
    app.CreatePerOwinContext(ApplicationDbContext.Create);
    app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
    app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);
    //rest of the code here
    app.UseSteamAuthentication("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); //works!
}