📄 userservice.cs
字号:
namespace Cjjer{
using System;
using System.Web.Services;
using System.Xml;
using System.Xml.XPath;
[WebService (Name="WebsCjjer",Description="一个验证用户登陆的web服务",Namespace="http://www.cjjer.com/webs/")]
public class UserService{
[WebMethod (Description ="输入用户名和密,返回权限Int值,0表示失败",MessageName="Login")]
public int Login(string UserName,string UserPassword){
return User.Check(UserName,UserPassword);
}
[WebMethod (Description ="新增用户名和密码,返回结果,0表示失败",MessageName="AddNew")]
public int AddNew(string UserName,string UserPassword){
if(User.Check(UserName,UserPassword)!=0) return 0;
return 1;
}
};
public class User{
const string _XmlUserData ="data\\user.xml";
public static string AppPath{
get{
string tempstr;
try{
tempstr = System.Web.HttpContext.Current.Server.MapPath(@"~");
}catch(System.Exception){//屏蔽.NET 版本不同时的错误信息
tempstr = System.Web.HttpContext.Current.Server.MapPath(@".");
}
return tempstr+"\\";
}
}
public static string XmlUserData{
get{return AppPath+_XmlUserData;}
}
public static int Check(string username,string userpassword){
int int_Re = 0;
try{
string xpath = @"descendant::user[name='"+username+"' and password='"+CodeString(userpassword)+"']/level";
int_Re= System.Convert.ToInt32(SelectSingleNodeValue(XmlUserData,xpath));
}catch(System.Exception){
int_Re = 0;
}
return int_Re;
}
public static string CodeString(string args){
return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(args, "Md5");//SHA1
}
public static string SelectSingleNodeValue(string FullXmlPath,string XPathString){
string returnstr =null;
XmlDocument doc = new XmlDocument();
try{
doc.Load(FullXmlPath);
XmlNode objNode = doc.SelectSingleNode(XPathString);
returnstr = objNode.LastChild.InnerText;
}catch(Exception){}
return returnstr;
}
};
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -