【发布时间】:2020-06-04 21:03:45
【问题描述】:
我有一个 android 应用程序,可以在 Xamarin Android 上在线运行,并使用在线 Web 服务和在线数据库我的问题是 Web 服务中的会话对于 localhost 来说是工作神,但是当我在服务器端使用它时它在这里不起作用当我在登录方法中使用会话和用户的 id 在另一种方法中使用它时,它是我的代码的一部分: 登录方式:
[WebMethod(EnableSession = true)]//Checks For Email And Password And Return The Type Of User
public string Login(string Email, string Password)
{
SqlDataReader reader;
Users us = new Users();
int userid = -1;
using (SqlConnection connection = new SqlConnection(DBConnection.ConnectionString))
{
SqlCommand cmd = new SqlCommand("SELECT User_ID FROM Users where Email=@Email AND Password=@Password");
cmd.CommandType = CommandType.Text;
cmd.Connection = connection;
cmd.Parameters.AddWithValue("@Email", Email);
cmd.Parameters.AddWithValue("@Password", Password);
connection.Open();
reader = cmd.ExecuteReader();
while (reader.Read())
{
userid = reader.GetInt32(0);
}
reader.Close();
connection.Close();
if (userid != -1)
{
Session["userid"] = userid;
return us.Usertype(userid);
}
else
return "Some Thing Went Wrong Please Check Your Informatin";
}
}
这是我在其中使用会话的方法:
[WebMethod(EnableSession = true)]//Return Shop id By Session
public string getshopid()
{
int iduser = 0;
iduser = Int32.Parse(Session["userid"].ToString());
int shopid =0;
try
{
SqlDataReader reader;
using (SqlConnection connection = new SqlConnection(DBConnection.ConnectionString))
{
SqlCommand cmd = new SqlCommand("SELECT Owner_Shop_ID FROM Owner where Owner_User_ID="+iduser);
cmd.CommandType = CommandType.Text;
cmd.Connection = connection;
connection.Open();
reader = cmd.ExecuteReader();
while (reader.Read())
{
shopid =reader.GetInt32(0);
}
reader.Close();
connection.Close();
}
}
catch (Exception ex)
{
string em = ex.Message;
}
return shopid.ToString();
}
有没有办法让会话在服务器端工作而不仅仅是在本地。我正在使用 smarterasp.net 服务器
【问题讨论】:
标签: c# asp.net session xamarin.android