簡體   English   中英

asp.net身份多用戶登錄

[英]asp.net identity multipe user login

嗨,我想知道是否可以使用 asp.net 身份在同一個 Web 應用程序中為兩個不同的站點提供多個登錄頁面

例如,有管理員登錄頁面和普通用戶登錄頁面。 一旦用戶登錄到管理員。 用戶還允許在不注銷管理站點的情況下再次登錄到普通用戶頁面。 順便說一句,用戶名會有兩個不同

有誰知道該怎么做? 這是對 asp.net 身份的限制,在整個 asp.net 中只允許一個登錄頁面嗎?

謝謝,

遲到但可能會幫助某人。 根據對類似問題的Pinpoint Answer ,您可以在 Startup 類中使用自定義執行以下操作:

    using System;
    using Microsoft.AspNet.Identity.Owin;
    using Microsoft.Owin;
    using Microsoft.Owin.Security.Cookies;
    using Owin;
    using Microsoft.AspNet.Identity;

然后將“RedirectIfAdmin”添加到 Provider

public partial class Startup {
        app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
        // Basic for site guest
            AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
            LoginPath = new PathString("/Account/Login"),
            LogoutPath = new PathString("/Account/Logout"),
            Provider = new CookieAuthenticationProvider {
                OnApplyRedirect = RedirectIfAdmin,
                OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
                    validateInterval: TimeSpan.FromMinutes(30),
                    regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
            }
        });
   }

並實現它以捕獲任何字符串或參數

    private static void RedirectIfAdmin(CookieApplyRedirectContext context)
    {
        // If Url contains 
        Uri absoluteUri;
        if (Uri.TryCreate(context.RedirectUri, UriKind.Absolute, out absoluteUri))
        {
            string path = context.Request.PathBase + context.Request.Path + context.Request.QueryString;
            if (path.Contains("/administration")) { 
                context.RedirectUri = "/administration/login.aspx" +
                new QueryString(context.Options.ReturnUrlParameter, context.Request.Uri.AbsoluteUri);
            }
        }

        context.Response.Redirect(context.RedirectUri);
    }

如果您想使用管理員帳戶登錄並下次使用用戶帳戶登錄,您可以使用其他瀏覽器或私人模式訪問該網站。 我不知道你想做什么,但如果只是為了測試,你可以這樣做。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM