简体   繁体   English

asp.net身份多用户登录

[英]asp.net identity multipe user login

Hi I wonder if it is possible to have multiple login page for two difference site in same web application by using asp.net identity嗨,我想知道是否可以使用 asp.net 身份在同一个 Web 应用程序中为两个不同的站点提供多个登录页面

For eg there are administrator login page and normal user login page.例如,有管理员登录页面和普通用户登录页面。 Once user login to admin already.一旦用户登录到管理员。 user also allow to login to normal user page again without logout admin site.用户还允许在不注销管理站点的情况下再次登录到普通用户页面。 Btw There will be two difference of username顺便说一句,用户名会有两个不同

Does anyone has any idea how to do it ?有谁知道该怎么做? Is this the limitation on asp.net identity to only allow one login page in the entire asp.net ?这是对 asp.net 身份的限制,在整个 asp.net 中只允许一个登录页面吗?

Thanks,谢谢,

Late but might help someone.迟到但可能会帮助某人。 According to Pinpoint Answer on a similar question, You can do something like this in Startup class with customization:根据对类似问题的Pinpoint Answer ,您可以在 Startup 类中使用自定义执行以下操作:

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

Then add a "RedirectIfAdmin" to Provider然后将“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))
            }
        });
   }

And implement it to catch any string or parameter并实现它以捕获任何字符串或参数

    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);
    }

If you want to login with Admin account and next login with user account you can just access the website with other browser or on private mode.如果您想使用管理员帐户登录并下次使用用户帐户登录,您可以使用其他浏览器或私人模式访问该网站。 I don't know what you want to do but if it's just for testing you can do this.我不知道你想做什么,但如果只是为了测试,你可以这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM