国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

使用webservice解決多系統登陸問題

2024-07-21 02:21:42
字體:
來源:轉載
供稿:網友
首先新建一個空項目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文件,然后在你的項目里面添加這個現有文件就可以了。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 台中市| 合阳县| 九江县| 辽源市| 南木林县| 旬邑县| 琼结县| 松原市| 旌德县| 灵寿县| 宣城市| 利川市| 会宁县| 巴林右旗| 威信县| 宁陵县| 临清市| 嫩江县| 莫力| 济源市| 玉龙| 莱阳市| 建阳市| 会东县| 抚松县| 曲阳县| 寿宁县| 吉林省| 石狮市| 花垣县| 桦川县| 永嘉县| 济源市| 贡山| 云安县| 河曲县| 漳平市| 商水县| 江安县| 韩城市| 卫辉市|