【问题标题】:Automatically stamping UserName of the User who created the a Sales record in the sales table自动标记在销售表中创建销售记录的用户的用户名
【发布时间】:2017-06-03 14:47:18
【问题描述】:

我想创建一个 ASP.NET MVC Web 应用程序,其中包括一个管理员帐户和几个用户帐户,用于注册和登录我使用默认帐户模型和控制器。谁能告诉我如何自动标记创建销售记录的用户的用户名,以及如何在我的索引页面中查看它。 对于销售,我有销售模式

{
public ApplicationUser ApplicationUser { get; set; }
    public int Id { get; set; }
    public string Po { get; set; }
    public long So { get; set; }
}

提前致谢。

【问题讨论】:

  • 将用户名存储在Session Variable中,并在保存数据的同时将其存储在表中。
  • 谢谢你的回答,我对asp.net很陌生,你能给我一些例子或参考吗?

标签: asp.net-mvc model-view-controller


【解决方案1】:

将用户名存储在会话中。

Session["UserId"] = usernameThatLoggedIn

稍后您可以使用它访问它

Session["UserId"]

如果你不在控制器中,你可以通过

HttpContext.Current.Session["UserId"]

【讨论】:

    猜你喜欢
    • 2012-09-12
    • 1970-01-01
    • 2023-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-06
    • 1970-01-01
    • 2023-01-20
    相关资源
    最近更新 更多