首先新建一個空項目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文件,然后在你的項目里面添加這個現有文件就可以了
|