• 安全性


    •完全适用ASP.NET的认证机制
    –可以使用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就会跑出异常“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;
        }
        
    }
  • 相关阅读:
    memory runs at single channel问题解决
    ASP php获取文件URL地址等方法
    zencart的modules下数据库操作templates排版和common首页引用
    php生成html 伪静态??
    Linux服务器自动备份压缩MySQL数据库的实用方法
    dos 命令集
    Zencart 500错误查找和解决方法
    破解JS加密:url unicode加密而已
    .htaccess 保护文件夹
    TCP 的那些事儿(上)
  • 原文地址:https://www.cnblogs.com/timy/p/1178274.html
Copyright © 2020-2023  润新知