加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

使用webservice解决多系统登陆问题

发布时间:2020-12-17 02:59:48 所属栏目:安全 来源:网络整理
导读:首先新建一个空项目project1 添加一个WebForm1 写如下代码 private void Page_Load(object sender,System.EventArgs e) ??{ ???if(Session["UserID"] != null) ???{ ????this.Response.Write(Session["UserName"].ToString()); ???} ???else ???{ ????this.R

首先新建一个空项目project1

添加一个WebForm1

写如下代码

private void Page_Load(object sender,System.EventArgs e)
??{
???if(Session["UserID"] != null)
???{
????this.Response.Write(Session["UserName"].ToString());
???}
???else
???{
????this.Response.Write("你输入的用户名或密码不正确!");
???}
??}

在项目名称上点又键,填加一个新webservie Login.asmx

代码文件如下

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;

namespace WorkFlow
{
?/// <summary>
?/// Login 的摘要说明。
?/// </summary>
?public class Login : System.Web.Services.WebService
?{
??WorkFlowWebUI.PortalLogin.FrameworkService loginService = new WorkFlowWebUI.PortalLogin.FrameworkService();
??public Login()
??{
???//CODEGEN:该调用是 ASP.NET Web 服务设计器所必需的
???InitializeComponent();
??}

??#region Component Designer generated code
??
??//Web 服务设计器所必需的
??private IContainer components = null;
????
??/// <summary>
??/// 设计器支持所需的方法 - 不要使用代码编辑器修改
??/// 此方法的内容。
??/// </summary>
??private void InitializeComponent()
??{
??}

??/// <summary>
??/// 清理所有正在使用的资源。
??/// </summary>
??protected override void Dispose( bool disposing )
??{
???if(disposing && components != null)
???{
????components.Dispose();
???}
???base.Dispose(disposing);??
??}??
??#endregion

??[WebMethod(EnableSession=true)]
??public?bool LoginMethod(string userName,string password)
??{
??????if(userName == "admin" & password== "admin")
????? {
?????? Session["userName"] = "admin"

?????? return true;??????

????? }

????? return false;
?}
}}

再建一个新web项目,WebProject1

添加Login的web引用,并在webForm1中调用LoginMethod,如果返回值为true重定向到project1的WebForm1.aspx

这里需要注意两点

一:在webService的特性里面需要加入(EnableSession=true)的描述

二:如果你是现在已经有的web项目将不允许你向其中添加新的webservice,这时候你要先在其它位置建立一个webservie文件,然后在你的项目里面添加这个现有文件就可以了。

写的不好,请各位原谅

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读