2011-11-27 42 views
11

Tôi có trong máy dev của tôi một WCF Client yêu cầu chứng chỉ và nó hoạt động tốt.
Sau khi triển khai đến máy chủ sản xuất tôi nhận được lỗi sau:ASP.NET - Mật khẩu mạng được chỉ định không chính xác

[CryptographicException: The specified network password is not correct.] 

DEV - Win7 32bit IIS 7.5
SẢN XUẤT - Win MÁY CHỦ 64bit 2008 IIS 7.5

Mặc dù không có mật khẩu giữa các mạng và không có mật khẩu chứng chỉ. (Tôi biết vì dev làm việc không có mật khẩu). Mật khẩu duy nhất mà tôi có là WCF giống với DEV.

CrmServiceClient crm = new CrmServiceClient("CrmServiceEndpoint"); 
crm.ClientCredentials.UserName.UserName = CrmConfigRepository.CrmUserName;//fine 
crm.ClientCredentials.UserName.Password = CrmConfigRepository.CrmPassword;//fine 
crm.ClientCredentials.ClientCertificate.Certificate = new X509Certificate2(Path); 
///THIS WONT WORK AS WELL 
crm.ClientCredentials.ClientCertificate.Certificate = new X509Certificate2(Path, "", X509KeyStorageFlags.Exportable); 

đây là toàn bộ đống

[CryptographicException: The specified network password is not correct. ] 
    System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr) +41 
    System.Security.Cryptography.X509Certificates.X509Utils._LoadCertFromFile(String fileName, IntPtr password, UInt32 dwFlags, Boolean persistKeySet, SafeCertContextHandle& pCertCtx) +0 
    System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromFile(String fileName, Object password, X509KeyStorageFlags keyStorageFlags) +372 
    System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(String fileName) +101 
    Externals.CrmConnection.Get() in C:\Users\avi\Documents\Visual Studio 2010\Projects\ExpressBroker\Externals\CrmConnection.cs:31 
    ExpressBroker.Models.ActionsMetadata.Handlers.LeadAccountHandler.Handle(BrokerAction brokerAction, ActionStep step, Dictionary`2 httpPostDataCollection) in C:\Users\avi\Documents\Visual Studio 2010\Projects\ExpressBroker\ExpressBroker\Models\ActionsMetadata\Handlers\LeadAccountHandler.cs:45 
    ExpressBroker.Models.ActionsMetadata.Handlers.BaseStepHandler.SecuredHandle(BrokerAction brokerAction, ActionStep step, Dictionary`2 httpPostDataCollection) in C:\Users\avi\Documents\Visual Studio 2010\Projects\ExpressBroker\ExpressBroker\Models\ActionsMetadata\Handlers\BaseStepHandler.cs:49 
    ExpressBroker.Models.ActionsMetadata.Handlers.HandlerInvoker.Invoke(BrokerAction brokerAction, ActionStep actionStep, Dictionary`2 stepValues) in C:\Users\avi\Documents\Visual Studio 2010\Projects\ExpressBroker\ExpressBroker\Models\ActionsMetadata\Handlers\StepServerInoker.cs:29 
    ExpressBroker.Controllers.LeadAccountController.Register(String step) in C:\Users\avi\Documents\Visual Studio 2010\Projects\ExpressBroker\ExpressBroker\Controllers\LeadAccountController.cs:28 
    lambda_method(Closure , ControllerBase , Object[]) +127 
    System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +264 
    System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +39 
    System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +129 
    System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +784922 
    System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +314 
    System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +784976 
    System.Web.Mvc.Controller.ExecuteCore() +159 
    System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +335 
    System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +62 
    System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +20 
    System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +54 
    System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +453 
    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +371 

Cảm ơn

+0

Đường dẫn được truyền trong hàm dựng X509Certificates là gì? Tôi nghĩ rằng đó là mật khẩu mạng truy cập vào tập tin chứng chỉ. – Simon

+0

Có thể trùng lặp? http://stackoverflow.com/q/899991/130352 –

Trả lời

32

Hãy thử điều này:

new X509Certificate2(Path, "", X509KeyStorageFlags.MachineKeySet); 

Dường như các nhà xây dựng X509Certificate2 cố gắng truy cập vào cửa hàng khóa riêng của địa phương người dùng (ngay cả khi tải PFX và khóa riêng nằm trong PFX). Với asp.net, hồ sơ người dùng thường không được tải, do đó lưu trữ khóa người dùng không tồn tại. Chỉ định MachineKeySet cho hàm khởi tạo xem cửa hàng khóa máy tính cục bộ luôn tồn tại.

+3

Đã lưu ngày của tôi ... họ nghĩ gì khi họ thực hiện API mã hóa. Đó không phải là thứ duy nhất trên các chứng chỉ mà tôi vấp phải. –

+0

cảm ơn bạn! Tôi chưa bao giờ nghĩ đến việc sử dụng lớp có tên xấu, nhưng chỉ có đây là giải pháp làm việc! – balint

+0

Cảm ơn vì điều này! – TheWebGuy

Các vấn đề liên quan