C# 你不必实施它。因为它都是模板的一部分。您所要做的就是添加声明,并将Users表添加到业务上下文中。感谢您提供了非常全面的答案。我将开始实施它。一旦我成功了(可能需要一段时间),我一定会让你知道。如果你创建了一个新的Asp.NETMVC项目,你就不必实现它。
C# 你不必实施它。因为它都是模板的一部分。您所要做的就是添加声明,并将Users表添加到业务上下文中。感谢您提供了非常全面的答案。我将开始实施它。一旦我成功了(可能需要一段时间),我一定会让你知道。如果你创建了一个新的Asp.NETMVC项目,你就不必实现它。,c#,asp.net-mvc,linq,asp.net-identity,C#,Asp.net Mvc,Linq,Asp.net Identity,你不必实施它。因为它都是模板的一部分。您所要做的就是添加声明,并将Users表添加到业务上下文中。感谢您提供了非常全面的答案。我将开始实施它。一旦我成功了(可能需要一段时间),我一定会让你知道。如果你创建了一个新的Asp.NETMVC项目,你就不必实现它。因为它都是模板的一部分。您所要做的就是添加声明,并将Users表添加到业务上下文中。 public ActionResult Index(int? id, int? csearchid) { var co
你不必实施它。因为它都是模板的一部分。您所要做的就是添加声明,并将Users表添加到业务上下文中。感谢您提供了非常全面的答案。我将开始实施它。一旦我成功了(可能需要一段时间),我一定会让你知道。如果你创建了一个新的Asp.NETMVC项目,你就不必实现它。因为它都是模板的一部分。您所要做的就是添加声明,并将Users表添加到业务上下文中。
public ActionResult Index(int? id, int? csearchid)
{
var companies = db.Companies
.OrderBy(i => i.CompanyName)
.Where(t => t.UserName == User.Identity.Name);
return View(companies);
public class Company
{
public int CompanyID { get; set; }
// Link naar de Userid in Identity: AspNetUsers.Id
[Display(Name = "Username")]
public string UserName { get; set; }
public string CompanyName { get; set;}
public string CompanyContactName { get; set; }
[DataType(DataType.EmailAddress)]
public string CompanyEmail { get; set; }
public string CompanyPhone { get; set; }
[Timestamp]
public byte[] RowVersion { get; set; }
//One to Many Navigatie links
public virtual ICollection<Csearch> Csearches { get; set; }
var companies = from c in db.Companies join u in db.AspNetUsers
on c.UserId equals u.UserId
orderby c.CompanyName
where u.UserName = User.Identity.Name
select c;
select new { Company = c, User = u.UserName };
public class Company
{
public int CompanyID { get; set; }
// Link naar de Userid in Identity: AspNetUsers.Id
// [Display(Name = "Username")] <-- Get rid of these
// public string UserName { get; set; } <-- get rid of these
...
}
public class ApplicationUser : IdentityUser
{
public int CompanyId { get; set; }
}
var companies = from c in db.Companies join u in db.AspNetUsers
on c.CompanyId equals u.CompanyId // <-- Change to this
orderby c.CompanyName
where u.UserName = User.Identity.Name
select c;
userManager.AddClaim(id, new Claim("UserId", UserId));
public class ApplicationUser : IdentityUser
{
public int UserId { get; set; }
public string DisplayUserName { get; set; }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
// Add custom user claims here
userIdentity.AddClaim(new Claim("UserId", UserId));
userIdentity.AddClaim(new Claim("DisplayUserName", DisplayUserName));
return userIdentity;
}
}
var user = (System.Security.Claims.ClaimsIdentity)User.Identity;
var userId = user.FindFirstValue("UserId");