且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在c#中从Web服务到登录页面获得响应

更新时间:2023-02-15 08:28:13

您好,



可能是你的期望匹配这个,



我使用WebSerive



AdminService.asmx



我的服务代码



Hi,

May be your expectation Match this,

I m Using WebSerive

AdminService.asmx

My Weservice Code

[WebService(Namespace = "http://tempuri.org/")]
   [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
   [System.ComponentModel.ToolboxItem(false)]
   // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
    [System.Web.Script.Services.ScriptService]
   public class AdminService: System.Web.Services.WebService
   {
        [WebMethod]
        public string DoLogin(string UserName,string Password)
        {
           //Your Login checking Logic
DataTable resFromDB = DBContext.GetDataTable("select * from tblUSer where UserName = "+UserName+" && Password = "+Password+");
 string resString = "";
            if (resFromDB.Rows.count >0 )
            {
               
                if(resFromDB.Rows[0]["UserType"]=="Admin")
                   resString = "Admin_1_"+resFromDB.Rows[0]["UserID"].toString();
                else
                   resString = "User_1_"+resFromDB.Rows[0]["UserID"].toString();

            }
            else
            {
                 resString = "Error_2_0";
            }
            return resString;
        }
   }





和Webserivce电话代码将是







And Webserivce Calling Code will be


protected void btnProcess_Click(object sender, EventArgs e)
        {
            
            AdminService ServiceObj = new AdminService();
string res = ServiceObj.DoLogin(txtUserName.Text, txtPassword.Text);
string successPart = res.split("_")[1];
            if (successPart  == 1)
            {
                //Login Success Logic
                if(res.split("_")[0]=="Admin")
                   Response.Redirect("AdminHome.aspx");
                else
                   Response.Redirect("EmployeeHome.aspx");
            }
            else
            {
                //Login Fail Logic
                Response.Redirect("Error.aspx");
            }
        }





注意:如果是Webservice External那么,需要添加Webservice作为参考



谢谢!

Siva Rm K



Note : If Webservice External then, need to Add Webservice as Reference

Thank you !
Siva Rm K


你应该这样做:



1.在数据库中添加时,按照您的提示存储不同类型的用户。

2.然后检查条件是否其管理员然后重定向到您想要的页面只有管​​理员才能看到。

3.为其他类型的用户做这些。
You should do these:

1. Store the different type of user as you have mentioned while adding in the database.
2. Then check the condition if its admin then redirect to a page you want only admin to see.
3. Do these for other to types of user.