繁体   English   中英

如何在 asp.net 的在线服务器上启用会话

[英]how to enable sessions on online server for asp.net

i have an android app that works online on Xamarin Android and with online web services and online database my problem is the sessions in web services is working god for localhost but when i use it on the server side it didn't work here is apart of当我在登录方法中使用 session 和在另一种方法中使用它的用户 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";
        }
    }

这是我在其中使用 session 的方法:

 [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();
    }

有没有办法让 session 在服务器端工作而不仅仅是在本地工作。 我正在使用 smarterasp.net 服务器

您似乎不能在共享主机上使用 session ,因为它会影响该服务器上的其他站点。 您可能需要直接联系您的托管服务提供商以询问您可以使用的其他解决方案。 基本上,您可以使用其他选项 cookies 或 Asp.net session Z9ED39E2EA931586B56A985A69EZEF。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM