使用 ASP.NET 标识在两个项目中重叠用户登录 [英] Overlap User Login in Two Projects with ASP.NET Identity

查看:15
本文介绍了使用 ASP.NET 标识在两个项目中重叠用户登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在asp.net身份中遇到了一个我无法理解的问题

I have a problem I can not understand in asp.net identity

应用以下步骤

  1. 创建两个空的 web 项目,它们的名称为:
    • WebApplication1
    • WebApplication2
  • 网络数据库1
  • WebDatabase2

我的问题是当我通过WebApplication1"中的User1"登录

My problem is when I Login by "User1" in "WebApplication1"

我发现 WebApplication2 是用 User1 登录的.

I find WebApplication2 is logged with User1.

尽管每个项目都有单独的数据库.

despite each project have separate database.

而且在 WebApplication2NO User1.

有什么问题吗?

请原谅我的英语不好!

推荐答案

当用户登录站点时,auth 中间件将登录的用户信息(包括 id、名称和角色)序列化到加密的 auth cookie 中.在后续访问中,框架只需解密和读取该信息,而不会访问数据库.

When a user signs into the site, the auth middleware serializes the logged in user information (including the id, name, and roles) into the encrypted auth cookie. On subsequent visits, the framework simply decrypts and reads that information without hitting the database.

默认情况下,跨 ASP.NET 应用程序使用相同的 cookie 名称.您看到发生的是 WebApp1 设置 cookie,WebApp2 读取它.这是因为它们位于同一个域(或 localhost)中,并且 cookie 在同一个域中的资源之间共享.

By default, the same cookie name is used across ASP.NET applications. What you see happening is WebApp1 setting the cookie, and WebApp2 reading it. This is because they're on the same domain (or localhost) and cookies are shared across resources on the same domain.

尝试更改应用程序中的 cookie 名称...

Try changing the cookie name in your applications...

app.UseCookieAuthentication(new CookieAuthenticationOptions
{
    // ...
    CookieName = "WebApp1AuthCookie"
});

这篇关于使用 ASP.NET 标识在两个项目中重叠用户登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆