Use WebService to solve multiple system login problems

zhaozj2021-02-16  43

First create a new empty project Project1

Add a WebForm1

Write the following code

Private void page_load (object sender, system.eventargs e) {if (session ["userid"]! = null) {this.response.write (session ["username"]. Tostring ());} else {this.Response .Write ("You entered the username or password is incorrect!");}}

In the project name, you can fill a new Webserve login.asmx

The code file is as follows

Using system; using system.componentmodel; using system.data; using system.web; using system.web.services;

Namespace Workflow {///

/// login's summary description. /// public class Login: System.Web.Services.WebService {WorkFlowWebUI.PortalLogin.FrameworkService loginService = new WorkFlowWebUI.PortalLogin.FrameworkService (); public Login () {// CODEGEN: the call is ASP.NET INITIALIZECMOMPONENT ();}

#Region Component Designer Generated Code // Web Server Designer The private icontainer component = null; ///

/// designer supports the required method - Do not modify // this method using the code editor content. /// private void initializecomponent ()}

///

/// Clean all the resources being used. /// 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;}}}

Built a new web project, WebProject1

Add login's web reference, and call LoginMethod in WebForm1, if the return value is true to redirect to Project1 WebForm1.aspx

Pay attention to two points here

One: Enjoy the description of EnableSession = true in the feature of WebService: If you are a Web project that you have now, you will not allow you to add new WebService, this time you have to build a webservie file in other locations. , Then add this existing file in your project.

Write a bad writing, please forgive

转载请注明原文地址:https://www.9cbs.com/read-24834.html

New Post(0)