2015-04-03 40 views
1

我正在使用Push Sharp的蘋果推送通知。它在我的本地機器上運行良好,具有開發和分發證書。當我在本地嘗試時,確實收到推送通知。但是,當我的代碼轉移到我的生產服務器(Godaddy的服務器),我收到了一條錯誤推夏普ios通知獲取分配證書錯誤「System.Security.Cryptography.CryptographicException」

System.Security.Cryptography.CryptographicException). 

PushBroker _pushBroker = new PushBroker(); 
       var appleCert = File.ReadAllBytes(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Certificates/App_AdHoc.p12")); 
       _pushBroker.RegisterAppleService(new ApplePushChannelSettings(true, appleCert, "pamten")); //Extension method 
       _pushBroker.QueueNotification(new AppleNotification() 
         .ForDeviceToken("Device Token") 
         .WithAlert("Message") 
         .WithBadge(0) 
         .WithSound("default") 
         ); 

下面是我在GoDaddy的服務器獲取錯誤。

ExceptionType": "System.Security.Cryptography.CryptographicException", 
5 "StackTrace": " at System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr)\r\n at System.Security.Cryptography.X509Certificates.X509Utils._LoadCertFromBlob(Byte[] rawData, IntPtr password, UInt32 dwFlags, Boolean persistKeySet, SafeCertContextHandle& pCertCtx)\r\n at System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromBlob(Byte[] rawData, Object password, X509KeyStorageFlags keyStorageFlags)\r\n at System.Security.Cryptography.X509Certificates.X509Certificate..ctor(Byte[] rawData, String password, X509KeyStorageFlags keyStorageFlags)\r\n at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(Byte[] rawData, String password, X509KeyStorageFlags keyStorageFlags)\r\n at PushSharp.Apple.ApplePushChannelSettings..ctor(Boolean production, Byte[] certificateData, String certificateFilePwd, Boolean disableCertificateCheck)\r\n at InStorePal.Controllers.InStorePalController.GetItemsList(GetItems obj)\r\n at lambda_method(Closure , Object , Object[])\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass13.<GetExecutor>b__c(Object instance, Object[] methodParameters)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.<>c__DisplayClass5.<ExecuteAsync>b__4()\r\n at System.Threading.Tasks.TaskHelpers.RunSynchronously[TResult](Func`1 func, CancellationToken cancellationToken)" 
6 } 

我已經試過很多像在GoDaddy的服務器這麼多次的文件夾,創建證書分發訪問權限的方式。

請幫幫我。 。 。

回答

0

我在GoDaddy Server中遇到同樣的問題。嘗試一次Azure或Amazon服務器。 它在Azure中爲我工作。

它是一個奇怪的問題和奇怪的解決方案。但它爲我工作。

0
public ActionResult ios() 
    { 
     var certi = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Certificatesgit.p12"); 
     var appleCert = System.IO.File.ReadAllBytes(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Certificatesgit.p12")); 

     ApnsConfiguration apnsConfig = new ApnsConfiguration(ApnsConfiguration.ApnsServerEnvironment.Production, appleCert, "password"); 

     string message = string.Empty; 
     var apnsBroker = new ApnsServiceBroker(apnsConfig); 

     apnsBroker.OnNotificationFailed += (notification, aggregateEx) => 
     { 
      aggregateEx.Handle(ex => 
      { 
       if (ex is ApnsNotificationException) 
       { 
        var notificationException = (ApnsNotificationException)ex; 
        var apnsNotification = notificationException.Notification; 
        var statusCode = notificationException.ErrorStatusCode; 
        var inner = notificationException.InnerException; 
        message = "IOS Push Notifications: Apple Notification Failed: ID=" + apnsNotification.Identifier + ", Code=" + statusCode + ", Inner Exception" + inner; 
       } 
       else 
       { 
        message = "IOS Push Notifications: Apple Notification Failed for some unknown reason : " + ex.InnerException; 
       } 
       return true; 
      }); 
     }; 

     apnsBroker.OnNotificationSucceeded += (notification) => 
     { 
      message = "IOS Push Notifications: Apple Notification Sent!"; 
     }; 

     apnsBroker.Start(); 
     try 
     { 
      string deviceToken = "4e16e1439d7f1a342ed5a8c92bf029503107c7a2bc3b92b794b22665affcf99c"; 

      apnsBroker.QueueNotification(new ApnsNotification 
      { 
       DeviceToken = deviceToken, 
       Payload = JObject.Parse("{\"aps\":{\"badge\":7}}") 
      }); 
     } 
     catch (Exception ex) 
     { 
      Console.Write(ex); 
     } 
     apnsBroker.Stop(); 

     return View(message); 
    }