我創建了一個全新的Web應用程序,例如「WebApplication1」 - WebForms的身份驗證設置爲個人用戶帳戶。我不會將一行代碼添加到自動生成的代碼模板中。我運行應用程序並註冊一個用戶「User1」並登錄 - 工作正常。爲什麼來自一個站點的ASP.NET身份登錄與同一臺計算機上的不同網站共享?
現在我創建另一個Web應用程序「WebApplication2」 - 相同的WebForms與設置爲個人用戶帳戶的身份驗證。再次沒有代碼,我運行該應用程序。現在我創建另一個用戶說「用戶2」 - 工作正常。
當兩個應用程序同時運行時,問題就開始了。 如果我以「User1」的身份登錄到第一個站點,當它甚至沒有註冊「User1」時,它會自動將第二個站點的Context.User.Identity設置爲「webApplication2」爲「User1」,反之亦然從一個站點註銷另一個站點註銷。
如何分享Context.User.Identity?
的代碼是一樣的 -
public static void SignIn(UserManager manager, ApplicationUser user, bool isPersistent){
IAuthenticationManager authenticationManager = HttpContext.Current.GetOwinContext().Authentication;
authenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
var identity = manager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie);
authenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent }, identity);
}
我真的很想念在ASP.Net身份是如何工作的,請幫我出一些基本知識。
在此先感謝。
很好的問題及以下優良接受的答案。建議重命名問題的標題更多的東西「的問題十歲上下」,像「爲什麼從一個站點ASP.NET身份登錄得到相同的機器上不同的網站共享?」 (或類似的東西...) – Funka
@Funka - 根據您的建議更改了問題。 –