.net - REST api 在已安装的服务器上不起作用
问题描述
我正在.Net 中实现一个 RestApi 并进行身份验证,我使用 sha512 验证密码,但是当我尝试在已安装的服务器上测试该 Api 时,它不起作用,但在其他系统或其他服务器上它工作正常。
我正在使用 Oauth 进行身份验证。
这是一些验证密码和 Web 配置文件的代码。
网络配置
修改密码
public static bool VerifyHash(string plainText, string hashAlgorithm, string hashValue)
{
// Convert base64-encoded hash value into a byte array.
byte[] hashWithSaltBytes = Convert.FromBase64String(hashValue);
// We must know size of hash (without salt).
int hashSizeInBits, hashSizeInBytes;
// Make sure that hashing algorithm name is specified.
if (hashAlgorithm == null)
hashAlgorithm = "";
// Size of hash is based on the specified algorithm.
switch (hashAlgorithm.ToUpper())
{
case "SHA384":
hashSizeInBits = 384;
break;
case "SHA512":
hashSizeInBits = 512;
break;
default: // Must be MD5
hashSizeInBits = 128;
break;
}
// Convert size of hash from bits to bytes.
hashSizeInBytes = hashSizeInBits / 8;
// Make sure that the specified hash value is long enough.
if (hashWithSaltBytes.Length < hashSizeInBytes)
return false;
// Allocate array to hold original salt bytes retrieved from hash.
byte[] saltBytes = new byte[hashWithSaltBytes.Length - hashSizeInBytes];
// Copy salt from the end of the hash to the new array.
for (int i = 0; i < saltBytes.Length; i++)
saltBytes[i] = hashWithSaltBytes[hashSizeInBytes + i];
// Compute a new hash string.
string expectedHashString = ComputeHash(plainText, hashAlgorithm, saltBytes);
// If the computed hash matches the specified hash,
// the plain text value must be correct.
return (hashValue == expectedHashString);
}
解决方案
我通过在配置文件中添加这行代码来解决我的问题。
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" />
推荐阅读
- ruby-on-rails - 仅使用 Ruby HTTPClient 的请求标头在 Ruby on Rails 中返回 405 http 状态代码(方法不允许)
- javascript - 来自前端(Angular)的FormData格式请求导致NodeJs后端中的未定义对象
- clang - LLVM IR - 从 IR 汇编格式到 C
- python - 我有一个 python 脚本,它列出了具有特定扩展名的文件。我想将这些文件的文件名打印到 txt 文件中。都在同一条路上
- python - 如果可以访问某个 URL,如何停止 python 程序
- sql - 存储用于 Kibana 可视化的不相关字段的正确方法是什么
- sql - 为什么我会收到此错误-“预期结果集但不是从查询中生成的.....”
- apache-spark - spark中的minHashLSH实现解释
- flutter - 在 CupertinoTabBar 的选项卡之间切换时如何停止 Stream
- sql - 大多数客户在哪里?