扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:中国IT实验室 来源:中国IT实验室 2007年9月7日
关键字: 身份验证 WebService Forms
System.Net.CookieContainer cookieContainer = new System.Net.CookieContainer();
MyService.WebService service = new App.MyService.WebService();
service.CookieContainer = cookieContainer;
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<compilation debug="false" />
<authentication mode="Forms">
<forms name="MyService" loginUrl="Login.asmx"></forms>
</authentication>
<authorization >
<deny users="?"/>
</authorization>
</system.web>
</configuration>
[WebMethod]
public bool Check(string userName,string password)

{
if (userName == "aaaaaa" && password == "123456")//添加验证逻辑
{
System.Web.Security.FormsAuthentication.SetAuthCookie(userName, false);
return true;
}
else
{
return false;
}
}
class Sample

{
System.Net.CookieContainer cookieContainer = new System.Net.CookieContainer();
public void Login()
{
MyServiceLogin.Login login = new App.MyServiceLogin.Login();
login.CookieContainer = cookieContainer;
login.Check("aaaaaa", "123456");
}
public void ShowHelloWorld()
{
MyService.WebService service = new App.MyService.WebService();
service.CookieContainer = cookieContainer;
Console.WriteLine(service.HelloWorld());
}
}如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。