asp.net mvc 4 accessing websecurity.Getuserid(user.identity.name) <p>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..</p> <p>Now in a function in the controller Licenca I instaciate an object ProcessoController and called the function on the ProcessoController...</p> <p>The problem is that user.identity.name is null.</p> <p>If from the ProcessoController I call the function to save the user id , user.identity.name gives me the username...</p> <p>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:</p> <p><a href="http://stackoverflow.com/questions/19515890/authentication-issue-when-debugging-in-vs2013-iis-express/">Authentication issue when debugging in VS2013 - iis express</a></p> <p>but it's not working... Is it possible to do this?</p> <p>What is the problem?</p> <p>Thanks in advance...</p> <p>Here goes the code:</p> <p>Fucntion SaveProcessoSoftware in the controller ProcessoProduto</p> <pre><code> public string SaveProcessoSoftware(int iIDProcesso, int iIDSoftware, int iIDTipoLicenciamento, List&lt;string&gt; NomeVariaveis, List&lt;string&gt; 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; } </code></pre> <p>Function SetLicenca...this is function where i save the user id...</p> <pre><code> 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);&lt;---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; } </code></pre> <p>From LicencaController i do this:</p> <pre><code> 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); } </code></pre> <p>Thanks again for the help..</p>