0

I am trying to access to the user id that is currently logged on... I have two controllers, LicencaController and ProcessoController. In the ProcessoController there is a function that saves the user id and some other stuff, this function was private, but in order to gain access I have change it to public..

Now in a function in the controller Licenca I instaciate an object ProcessoController and called the function on the ProcessoController...

The problem is that user.identity.name is null.

If from the ProcessoController I call the function to save the user id , user.identity.name gives me the username...

If from the LicencaController I call the function to save the user id that is declared in the ProcessoController, it gives me null... I have tried other solutions like the one in this topic:

Authentication issue when debugging in VS2013 - iis express

but it's not working... Is it possible to do this?

What is the problem?

Thanks in advance...

Here goes the code:

Fucntion SaveProcessoSoftware in the controller ProcessoProduto

 public string SaveProcessoSoftware(int iIDProcesso, int iIDSoftware, int iIDTipoLicenciamento, 
 List<string> NomeVariaveis, List<string> ValorVariaveis, string sNrFactura, string       sIDLicencaInicial, string sDescricaoTipoSoftware)
    {
        int iIDFactura = GetIDFactura(sNrFactura);
        string sIDLicenca = SetLicenca(iIDSoftware, sIDLicencaInicial, sDescricaoTipoSoftware);
        ProcessoProdutos objProcSoft = new ProcessoProdutos();
        objProcSoft.IDProcesso = iIDProcesso;
        objProcSoft.IDLicencaSoftware = sIDLicenca;
        objProcSoft.IDFactura = iIDFactura;
        objProcSoft.Rem = 0;
        objProcSoft.IDU = WebSecurity.CurrentUserId;//  .GetUserId(User.Identity.Name);
        objProcSoft.TStamp = GetDateTimeFromSqlSytem();
        db.ProcessoProdutos.Add(objProcSoft);
        db.SaveChanges();
        if (NomeVariaveis != null)
            SaveVariaveis(sIDLicenca, iIDTipoLicenciamento, NomeVariaveis, ValorVariaveis);
        return sIDLicenca;
    }

Function SetLicenca...this is function where i save the user id...

    public string SetLicenca(int iIDSoftware, string sIDLicenca, string sDescricaoTipoSoftware)
    {
        string LastTableIDLicenca = "";
        Licenca Lic = new Licenca();
        Lic.IDProduto = iIDSoftware;
        Lic.Estado = 4;
        Lic.Observacoes = "";
        Lic.DataValidade = DateTime.MaxValue;
        Lic.Validado = 2;
        Lic.IDValidado = 0;
        Lic.IDTitular = 0;
        Lic.Rem = 0;
        Lic.IDU = WebSecurity.GetUserId(User.Identity.Name);<---error
        Lic.TStamp = GetDateTimeFromSqlSytem();
        Lic.IDLicenca = new Licenciamento_v2.Areas.Idonic.IDLicencaGenerator().GenerateCharID(8);
        db.Licencas.Add(Lic);
        int t = SaveLicenca();
        if (t == -1)
            SetLicenca(iIDSoftware, sIDLicenca, sDescricaoTipoSoftware);
        else
        {
            LastTableIDLicenca = Lic.IDLicenca;
            //obter o id introduzido e actualizar o campo idInicial
            if (sDescricaoTipoSoftware.Equals("Software") == true)
            {
                Lic = db.Licencas.Find(LastTableIDLicenca);
                if (sIDLicenca != "")
                {
                    Licenca LicAnt = db.Licencas.Find(sIDLicenca);
                    Lic.IDInicial = LicAnt.IDInicial;
                }
                else
                {
                    Lic.IDInicial = LastTableIDLicenca;
                }
                db.SaveChanges();
            }
        }
        return LastTableIDLicenca;
    }

From LicencaController i do this:

 public void SaveSoftwareToLicenca()
 {
 int sessionIDProcesso = (int)Session["EditIDProcesso"];
 ProcessoController procCont = new ProcessoController();
 procCont.ChangeProcessoProdutoStatus(sessionIDProcesso, t.rowId, 1);
 procCont.ChangeLicencaEstado(t.rowId, 3);
 procCont.ChangeLicencaVariaveisStatus(t.rowId, 1);
 Session["IDLicenca"] = procCont.SaveProcessoSoftware(sessionIDProcesso, t.row.IDSoftware, t.row.IDNivelDeLicenciamento, t.row.NomeVariaveis, t.row.ValorVariaveis, t.row.NumeroFactura, t.row.IDLicenca, t.row.DescricaoTipoDeSoftware);
 }

Thanks again for the help..

Community
  • 1
  • 1
Hugo Silva
  • 352
  • 8
  • 26

0 Answers0