Web主机服务器中使用非对称绑定的访问被拒绝错误 - .NET

时间:2014-04-11 03:03:02

标签: asp.net web-services security access-denied x509certificate2

当我尝试发出Web服务请求时,我收到了拒绝访问权限错误。 Web服务需要非对称安全绑定。通过引用引用Web服务的.NET dll的网页进行调用。所有这些在我们的服务器上工作正常,但我们将它加载到我们遇到此错误的网络托管公司。 我的理论是,无论GetKeyPairHelper方法是什么,它都需要能够编写文件来执行它,而我们无法访问它尝试写入的位置。这家公司的支持人员为我们留下了痕迹,这些是最后两行:

  

06:03.1 w3wp.exe 5860 CreateFile C:\ ProgramData NAME COLLISION> Desired Access:Read Data / List Directory,Synchronize,Disposition:Create,Options:> Directory,Synchronous IO Non-Alert,Open Reparse Point,属性:N,ShareMode:Read,> Write,AllocationSize:0

     

06:03.1 w3wp.exe 5860 CreateFile C:\ ProgramData ACCESS DENIED> Desired Access:Read Attributes,Disposition:Open,Options:Open Reparse Point,> Attributes:n / a,ShareMode:Read,Write,Delete ,AllocationSize:不适用

看起来有些东西试图写信给C:\ProgramData但是什么?为什么?我该如何解决这个问题?我希望有一些方法可以配置它,因此它不必编写文件。也许这项工作可以在记忆中执行,也可以指向我们有权访问的区域。

堆栈跟踪:

  

错误:访问被拒绝。 :服务器堆栈跟踪:   在System.Security.Cryptography.Utils.CreateProvHandle(CspParameters parameters,Boolean randomKeyContainer)   在System.Security.Cryptography.Utils.GetKeyPairHelper(CspAlgorithmType keyType,CspParameters参数,Boolean randomKeyContainer,Int32 dwKeySize,SafeProvHandle& safeProvHandle,SafeKeyHandle& safeKeyHandle)   在System.Security.Cryptography.RSACryptoServiceProvider.GetKeyPair()   在System.Security.Cryptography.RSACryptoServiceProvider..ctor(Int32 dwKeySize,CspParameters parameters,Boolean useDefaultKeySize)   在System.Security.Cryptography.X509Certificates.X509Certificate2.get_PrivateKey()   在System.IdentityModel.Tokens.X509AsymmetricSecurityKey.get_PrivateKey()   at System.IdentityModel.Tokens.X509AsymmetricSecurityKey.GetSignatureFormatter(String algorithm)   在System.IdentityModel.SignedXml.ComputeSignature(SecurityKey signingKey)   在System.ServiceModel.Security.WSSecurityOneDotZeroSendSecurityHeader.CompletePrimarySignatureCore(SendSecurityHeaderElement [] signatureConfirmations,SecurityToken [] signedEndorsingTokens,SecurityToken [] signedTokens,SendSecurityHeaderElement [] basicTokens)   System.ServiceModel.Security.SendSecurityHeader.CompleteSecurityApplication()中的System.ServiceModel.Security.SendSecurityHeader.CompleteSignature()   在System.ServiceModel.Security.SecurityAppliedMessage.OnWriteMessage(XmlDictionaryWriter writer)   在System.ServiceModel.Channels.Message.WriteMessage(XmlDictionaryWriter writer)   在System.ServiceModel.Channels.Message.WriteMessage(XmlWriter writer)   at CustomMessageEncoder.CustomTextMessageEncoder.WriteMessage(消息消息,Int32 maxMessageSize,BufferManager bufferManager,Int32 messageOffset)   在C:\ xxxxx \ CustomEncoders \ CustomTextMessageEncoder.cs:第86行

代码:

public override ArraySegment<byte> WriteMessage(Message message, int maxMessageSize, BufferManager bufferManager, int messageOffset)
{
    MemoryStream stream = new MemoryStream();
    XmlWriter writer = XmlWriter.Create(stream, this.writerSettings);
    message.WriteMessage(writer); //'line 86' in stacktrace.  
    writer.Close();

    byte[] messageBytes = stream.GetBuffer();
    int messageLength = (int)stream.Position;
    stream.Close();

    int totalLength = messageLength + messageOffset;
    byte[] totalBytes = bufferManager.TakeBuffer(totalLength);
    Array.Copy(messageBytes, 0, totalBytes, messageOffset, messageLength);
    //maybe parse message around here...
    ArraySegment<byte> byteArray = new ArraySegment<byte>(totalBytes, messageOffset, messageLength);
    return byteArray;
}

1 个答案:

答案 0 :(得分:0)

这里发生的事情是托管公司在共享服务器上托管我们的网站,因此理所当然地拒绝访问C:\ ProgramData文件夹,该目录下面包含C:\ ProgramData \ Microsoft \ Crypto \ RSA \ MachineKeys这是您需要访问的文件夹,以便使用基于证书的安全性。他们的解决方案是仅允许访问我们的应用程序池的此文件夹。像魅力一样。