【问题标题】:How to secure custom Web service with VB.NET?如何使用 VB.NET 保护自定义 Web 服务?
【发布时间】:2012-04-20 18:33:20
【问题描述】:

我使用 Visual Studio 2010 在 VB 中构建了一个简单的 Web 服务。现在我想通过用户名和密码来保护这个 Web 服务。如果用户名和密码匹配,用户可以使用/查看内容。我的网络服务如下;

Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Web.Script.Services

' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
<System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class Convert
    Inherits System.Web.Services.WebService

    <WebMethod()> _
    Public Function HelloWorld() As String
        Return "Hello World"
    End Function

    <System.Web.Services.WebMethod()> _
    <ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _
    Public Function FahrenheitToCelsius(ByVal Fahrenheit As Double) _
           As Double
        Return ((Fahrenheit - 32) * 5) / 9
    End Function

    <System.Web.Services.WebMethod()> _
    <ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _
    Public Function CelsiusToFahrenheit(ByVal Celsius As Double) _
            As Double
        Return ((Celsius * 9) / 5) + 32
    End Function
End Class 

我正在使用 JavaScript 使用 Dojo 来调用它。有人可以指导我如何保护它。

【问题讨论】:

  • ASMX 是一项遗留技术,不应用于新开发。 WCF 应该用于 Web 服务客户端和服务器的所有新开发。一个提示:微软已经在 MSDN 上停用了ASMX Forum

标签: javascript asp.net web-services security ws-security


【解决方案1】:

这证明了一种合理的方法: http://www.thebuzzmedia.com/designing-a-secure-rest-api-without-oauth-authentication/

简而言之,您发送用户名、散列密码、客户端时间戳和函数参数,以及所有这些的散列以及请求 URL 和私钥。服务器重新创建哈希以验证没有任何更改,检查时间戳是否在可接受的范围内,然后执行函数。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-01-03
    • 1970-01-01
    • 2011-06-16
    • 2015-06-16
    • 1970-01-01
    • 1970-01-01
    • 2017-07-12
    • 1970-01-01
    相关资源
    最近更新 更多