zoukankan      html  css  js  c++  java
  • 安全性

    •完全适用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;
        }
        
    }
  • 相关阅读:
    关于课内外读物的建议
    c# Aes加解密
    web api 如何通过接收文件流的方式,接收客户端及前端上传的文件
    c# 文件夹权限
    mysql 8创建远程访问用户以及连接mysql速度慢的解决方法
    为什么读书?读书让我们明心见性!
    大部分教程不会告诉你的 12 个 JS 技巧
    nuget包管理nuget服务器发布包时出现请求报错 406 (Not Acceptable)
    Python 实现毫秒级淘宝、京东、天猫等秒杀抢购脚本
    eos的资源和工具列表
  • 原文地址:https://www.cnblogs.com/timy/p/1178274.html
Copyright © 2011-2022 走看看