如何在c#中从Web服务到登录页面获得响应 [英] how to get response from web service to login page in c#

查看:55
本文介绍了如何在c#中从Web服务到登录页面获得响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

告诉我如何在登录页面中使用Web服务并使用响应成功登录

tell me how to use web service in login page and make successful login with response

推荐答案

您好,



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



我使用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.


这篇关于如何在c#中从Web服务到登录页面获得响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆