C# 如何使WebSecurity.CreateUserAndAccount在没有唯一用户名的情况下工作

C# 如何使WebSecurity.CreateUserAndAccount在没有唯一用户名的情况下工作,c#,asp.net,asp.net-mvc,asp.net-mvc-4,C#,Asp.net,Asp.net Mvc,Asp.net Mvc 4,我创建了一个默认的ASP.NET MVC 4项目,其中包含一个使用表单身份验证的帐户控制器。 现在,我想让用户帐户不仅在给定的系统实例中是唯一的,每个用户都有自己的SystemInstanceId,您可以: 可以在公司1网站地址/公司1的系统实例中使用用户名1,在公司2网站地址/公司2的系统实例中使用相同的用户名1 无法在一个系统实例中使用username1 在AccountController中,我使用以下代码,但它不能按我所希望的那样工作: WebSecurity.CreateUserAn

我创建了一个默认的ASP.NET MVC 4项目,其中包含一个使用表单身份验证的帐户控制器。 现在,我想让用户帐户不仅在给定的系统实例中是唯一的,每个用户都有自己的SystemInstanceId,您可以:

可以在公司1网站地址/公司1的系统实例中使用用户名1,在公司2网站地址/公司2的系统实例中使用相同的用户名1 无法在一个系统实例中使用username1

在AccountController中,我使用以下代码,但它不能按我所希望的那样工作:

WebSecurity.CreateUserAndAccount(
    model.UserName, 
    model.Password, 
    propertyValues: new { SystemInstanceId = systemInstanceRepository.GetCurrentSystemInstanceId(RouteSegmentHelpers.GetSystemInstanceSegment(RouteData)) }
);
上面的代码使我无法在数据库表中为两个不同的系统实例注册相同的用户名,这与我的设计背道而驰,因为我希望用户能够为不同的公司使用相同的登录名

WebSecurity.CreateUserAndAccount(
    model.UserName, 
    model.Password, 
    propertyValues: new { SystemInstanceId = systemInstanceRepository.GetCurrentSystemInstanceId(RouteSegmentHelpers.GetSystemInstanceSegment(RouteData)) }
);