I wonder if it is possible to record a session using a simple C # class. Action consists in:
- Access the URL (WCF).
- Saves session.
- Return User.
I have the following class
namespace BLL.Rules
{
public class UsuarioRules
{
public Usuarios login(string Senha)
{
try
{
UsuariosDAL ud = new UsuariosDAL();
GenerateHash helperMD5 = new GenerateHash();
var senhaMD5 = helperMD5.CreateHashMD5(Senha.ToString());
var u = ud.ListarPorSenha(senhaMD5);
if (u != null)
{
string teste = "teste";
HttpContext.Current.Session["Id"] = teste;
}
else
{
HttpContext.Current.Session.Abandon();
}
return u;
}
catch (Exception ex)
{
string exString = ex.ToString();
}
}
}
This class is accessed by service
namespace WCF
{
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Usuario : IUsuario
{
public Usuarios login(string senha)
{
try
{
UsuarioRules ur = new UsuarioRules();
Usuarios u = ur.login(senha);
return u;
}
catch (Exception ex)
{
throw new Exception("Erro ao realizar login: " + ex);
}
}
}
}
The time that will create the session returns the error.
- Object reference not set to an instance of an object.
Please help, thank you.