一. 使用ASP.Net Forms模式实现
1. 配置web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<compilation debug="false" />
<authentication mode="forms">
<forms name="login" loginurl="login.asmx"></forms>
</authentication>
<authorization >
<deny users="?"/>
</authorization>
</system.web>
</configuration>
2. 编写login.asmx
[WebMethod]
public bool Check(String name, String password)
{
if (name == "111" && password == "111")
{
System.Web.Security.FormsAuthentication.SetAuthCookie("111", false);
return true;
}
else
{
return false;
}
}
3. 客户端编码
System.Net.CookieContainer cc = new System.Net.CookieContainer();
localhost1.login login = new Test.localhost1.login();
login.CookieContainer = cc;
login.Check("111", "111");
localhost.Service service = new Test.localhost.Service();
service.CookieContainer = cc;
MessageBox.Show(service.HelloWorld());