将默认名称声明更改为其他内容

时间:2018-10-25 07:45:05

标签: asp.net-mvc owin saml adfs

一旦发布ADFS索赔,如何将用户名(HttpContext.Current.User.Identity.Name)更改为

http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upnhttp://schemas.xmlsoap.org/ws/2005/05/identity/claims/name

我在App_Start中的Startup.Auth.cs是

public partial class Startup
{


    private static string realm = ConfigurationManager.AppSettings["ida:Wtrealm"];
    private static string adfsMetadata = ConfigurationManager.AppSettings["ida:ADFSMetadata"];


    public void ConfigureAuth(IAppBuilder app)
    {



        app.UseCookieAuthentication(new CookieAuthenticationOptions
        {

            CookieManager = new SystemWebCookieManager()
        });

        app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

        app.UseCookieAuthentication(new CookieAuthenticationOptions());

        app.UseWsFederationAuthentication(
            new WsFederationAuthenticationOptions
            {
                Wtrealm = realm,
                MetadataAddress = adfsMetadata
            });
    }
}

,startup.cs是

 public partial class Startup
{
    public void Configuration(IAppBuilder app)
    {
        ConfigureAuth(app);
        IEnumerable<Claim> claims = ClaimsPrincipal.Current.Claims;
    }
}

最后,如果我访问HttpContext.Current.User.Identity.Name,我应该得到upn的值而不是Name

0 个答案:

没有答案