安全性
                            
                            
                            ?完全適用ASP.NET的認(rèn)證機(jī)制
–可以使用FormsAuthentication
?WebService方法可以操作Cookie
–Impersonation
–PrincipalPermission
aspx
????<form?id="form1"?runat="server">
????????<asp:ScriptManager?runat="server"?ID="ScriptManager1"?ScriptMode="Debug">
????????????<Services>
????????????????<asp:ServiceReference?Path="Services/SecurityService.asmx"?InlineScript="true"?/>
????????????</Services>
????????</asp:ScriptManager>????
????????
????????<input?type="button"?value="Call"?onclick="call()"?/>
????
????????<script?language="javascript"?type="text/javascript">
????????????function?call()
????????????{
????????????????SecurityService.HelloWorld(onSucceeded);
????????????}
????????????
????????????function?onSucceeded(result)
????????????{
????????????????alert(result);
????????????}
????????</script>????
????</form>
cs
????protected?void?Page_Load(object?sender,?EventArgs?e)
????{
????????FormsAuthentication.SetAuthCookie("Jeffrey?Zhao",?false);
????} 如果不加上這一句,WebService就會跑出異?!?font face="Verdana">Please log in first”
SecurityService.asmx
<%@?WebService?Language="C#"?Class="SecurityService"?%>
using?System;
using?System.Web;
using?System.Web.Services;
using?System.Web.Services.Protocols;
using?System.Web.Script.Services;
[WebService(Namespace?=?"http://tempuri.org/")]
[WebServiceBinding(ConformsTo?=?WsiProfiles.BasicProfile1_1)]
[ScriptService]
public?class?SecurityService?:?System.Web.Services.WebService
{
????[WebMethod]
????public?string?HelloWorld()
????{
????????if?(!HttpContext.Current.User.Identity.IsAuthenticated)
????????{
????????????throw?new?ApplicationException("Please?log?in?first.");
????????}
????????
????????return?"Hello,?"?+?HttpContext.Current.User.Identity.Name;
????}
????
}
                        
                        
                        –可以使用FormsAuthentication
?WebService方法可以操作Cookie
–Impersonation
–PrincipalPermission
aspx
????<form?id="form1"?runat="server">
????????<asp:ScriptManager?runat="server"?ID="ScriptManager1"?ScriptMode="Debug">
????????????<Services>
????????????????<asp:ServiceReference?Path="Services/SecurityService.asmx"?InlineScript="true"?/>
????????????</Services>
????????</asp:ScriptManager>????
????????
????????<input?type="button"?value="Call"?onclick="call()"?/>
????
????????<script?language="javascript"?type="text/javascript">
????????????function?call()
????????????{
????????????????SecurityService.HelloWorld(onSucceeded);
????????????}
????????????
????????????function?onSucceeded(result)
????????????{
????????????????alert(result);
????????????}
????????</script>????
????</form>
cs
????protected?void?Page_Load(object?sender,?EventArgs?e)
????{
????????FormsAuthentication.SetAuthCookie("Jeffrey?Zhao",?false);
????} 如果不加上這一句,WebService就會跑出異?!?font face="Verdana">Please log in first”
SecurityService.asmx
<%@?WebService?Language="C#"?Class="SecurityService"?%>
using?System;
using?System.Web;
using?System.Web.Services;
using?System.Web.Services.Protocols;
using?System.Web.Script.Services;
[WebService(Namespace?=?"http://tempuri.org/")]
[WebServiceBinding(ConformsTo?=?WsiProfiles.BasicProfile1_1)]
[ScriptService]
public?class?SecurityService?:?System.Web.Services.WebService
{
????[WebMethod]
????public?string?HelloWorld()
????{
????????if?(!HttpContext.Current.User.Identity.IsAuthenticated)
????????{
????????????throw?new?ApplicationException("Please?log?in?first.");
????????}
????????
????????return?"Hello,?"?+?HttpContext.Current.User.Identity.Name;
????}
????
}
轉(zhuǎn)載于:https://www.cnblogs.com/timy/archive/2008/04/30/1178274.html
總結(jié)
                            
                        - 上一篇: 新一代网络模式Web 2.0火爆发展
 - 下一篇: web策略类游戏开发(四)一个可以承载万