I am encoding an authentication service that has several methods. One method is ChangePassword. I want, when any authority wants to change the password, log in earlier. To do this, I want to have a session identifier and check it before changing the password.
How can I do this and do you have this session?
EDIT 1)
I am writing this code, but my session is null every time I want to get its value:
Grade:
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
public class Service2 : IService2
{
string result
{
get
{
if (HttpContext.Current.Session["Result"] != null)
return HttpContext.Current.Session["Result"].ToString();
return "Session Is Null";
}
set
{
HttpContext.Current.Session["Result"] = value;
}
}
public void SetSession(string Val)
{
result = Val;
}
public string GetSession()
{
return result;
}
interface:
[ServiceContract(SessionMode = SessionMode.Required)]
public interface IService2
{
[OperationContract]
void SetSession(string Val);
[OperationContract]
string GetSession();
}
web.config
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
EDIT 2)
I wrote this code, but it does not work:
private void button1_Click(object sender, EventArgs e)
{
MyService2.Service2Client srv = new MyService2.Service2Client();
textBox1.Text = srv.GetSession();
}
private void button2_Click(object sender, EventArgs e)
{
MyService2.Service2Client srv = new MyService2.Service2Client();
srv.SetSession(textBox1.Text);
textBox1.Clear();
}
every time I want to get a Session value, I get "Session Is Null" .Why?
source
share