• 安全性


    •完全适用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;
        }
        
    }
  • 相关阅读:
    centos npm run build 报错
    python base64
    Emacs 常用命令
    linux 删除文件腾出空间 遇到的问题
    网速查看工具
    linux 查看当前文件夹下的文件大小
    Docker 私有仓库push
    Harbor:Http: server gave HTTP response to HTTPS client & Get https://192.168.2.119/v2/
    docker 私有仓库搭建
    linux 修改时间
  • 原文地址:https://www.cnblogs.com/timy/p/1178274.html
Copyright © 2020-2023  润新知