How to get save current user Company In Supplier Table RRS feed

  • Question

  • User-2035378889 posted

    Hello Every One 

    I want to gent current user Company  and save in all Table where is field name company

    am using this 

    public ActionResult AddSupplier(SupplierModel model,UserAccountModel)
                if (ModelState.IsValid)
                    var username = System.Web.HttpContext.Current.User.Identity.Name;
                    model.Company = username;
                    return RedirectToAction("SupplierList");
                return View(model);

    var username = System.Web.HttpContext.Current.User.Identity.Name

    above line return user Email 

    but I need user company

    this is my user Account Model Class

    using PharmaApp.Core.DataModel.Base;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;
    using System.ComponentModel.DataAnnotations.Schema;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace PharmaApp.Core.DataModel
        public class UserAccountModel : BaseModel
            public string Name { get; set; }
            public string Email { get; set; }
            public string Password  { get; set; }
            public string Role { get; set; }
            public new string Company { get; set; }

     I need  this 

     public new string Company { get; set; }

    thanks To All

    Sunday, January 17, 2021 7:58 PM

All replies

  • User-1545767719 posted

    It seems that you do not use the ASP.NET Identity but your own user authentication system you developed by yourself. If so nobody will be able to answer to your question as nobody knows your own system. 

    Monday, January 18, 2021 12:53 AM
  • User-1330468790 posted



    Since we don't know how you implement the identity system, we could only suggest two directions to get the desired claim 'company' while you might be able to use a more elegant way. 

    1. Use the name (email) as an identity(id) to fetch the user information from the table "UserAccount" by connecting the database or using dbcontext.
    2. Check what the class type of System.Web.HttpContext.Current.User.Identity to see if it is possible to fetch the claim "Company" directly. The rationality is that it returns an object which implements the interface IIdentity Interface. For example, ClaimsIdentity Class allows you to access the Claims collection and gets the value for a specific field.


    Hope helps.

    Best regards,


    Monday, January 18, 2021 2:24 AM