2014-10-21 65 views
0

我無法在IIS 7.5上使用SignalR演示Move Shape工作。它適用於我在IIS Express和Visual Studio 2013下的開發PC上。客戶端屬性未定義在IIS 7.5下的SignalR移動形狀演示?

我目前正在將項目中的Move.html文件和/腳本複製到IIS 7.5 PC上的wwwroot目錄中。

當我從http:// localhost/Move.html加載IIS PC上的Move.html,我得到的JavaScript以下錯誤:

Uncaught TypeError: Cannot read property 'client' of undefined

這是我前行var moveShapeHub = $.connection.moveShapeHub,返回moveShapeHub爲未定義的結果。

Move.html:

<!DOCTYPE html> 
<html> 
<head> 
    <title>SignalR MoveShape Demo</title> 
    <style> 
     #shape { 
      width: 100px; 
      height: 100px; 
      background-color: #FF0000; 
     } 
    </style> 
</head> 
<body> 
    <script src="Scripts/jquery-1.10.2.min.js"></script> 
    <script src="Scripts/jquery-ui-1.10.3.min.js"></script> 
    <script src="Scripts/jquery.signalR-2.1.2.min.js"></script> 
    <script src="/signalr/hubs"></script> 
    <script> 
     $(function() { 
      var moveShapeHub = $.connection.moveShapeHub, 
       $shape = $("#shape"), 
       // Send a maximum of 10 messages per second 
       // (mouse movements trigger a lot of messages) 
       messageFrequency = 10, 
       // Determine how often to send messages in 
       // time to abide by the messageFrequency 
       updateRate = 1000/messageFrequency, 
       shapeModel = { 
        left: 0, 
        top: 0 
       }, 
       moved = false; 
      moveShapeHub.client.updateShape = function (model) { 
       shapeModel = model; 
       // Gradually move the shape towards the new location (interpolate) 
       // The updateRate is used as the duration because by the time 
       // we get to the next location we want to be at the "last" location 
       // We also clear the animation queue so that we start a new 
       // animation and don't lag behind. 
       $shape.animate(shapeModel, { duration: updateRate, queue: false }); 
      }; 
      $.connection.hub.start().done(function() { 
       $shape.draggable({ 
        drag: function() { 
         shapeModel = $shape.offset(); 
         moved = true; 
        } 
       }); 
       // Start the client side server update interval 
       setInterval(updateServerModel, updateRate); 
      }); 
      function updateServerModel() { 
       // Only update server if we have a new movement 
       if (moved) { 
        moveShapeHub.server.updateModel(shapeModel); 
        moved = false; 
       } 
      } 
     }); 
    </script> 

    <div id="shape" /> 
</body> 
</html> 

因此,它是能夠找到/ signalr /集線器和其他定義,但IIS 7.5下無法解決的樞紐,但它工作在IIS快遞。

我錯過IIS 7.5下的一些設置嗎?

在IIS 7.5下需要什麼設置步驟?

這可以在IIS 7.5下工作嗎?

這裏是基地代碼(直接從演示):

using System; 
using System.Threading; 
using Microsoft.AspNet.SignalR; 
using Newtonsoft.Json; 

namespace MoveShapeDemo 
{ 
    public class Broadcaster 
    { 
     private readonly static Lazy<Broadcaster> _instance = 
      new Lazy<Broadcaster>(() => new Broadcaster()); 
     // We're going to broadcast to all clients a maximum of 25 times per second 
     private readonly TimeSpan BroadcastInterval = 
      TimeSpan.FromMilliseconds(40); 
     private readonly IHubContext _hubContext; 
     private Timer _broadcastLoop; 
     private ShapeModel _model; 
     private bool _modelUpdated; 
     public Broadcaster() 
     { 
      // Save our hub context so we can easily use it 
      // to send to its connected clients 
      _hubContext = GlobalHost.ConnectionManager.GetHubContext<MoveShapeHub>(); 
      _model = new ShapeModel(); 
      _modelUpdated = false; 
      // Start the broadcast loop 
      _broadcastLoop = new Timer(
       BroadcastShape, 
       null, 
       BroadcastInterval, 
       BroadcastInterval); 
     } 
     public void BroadcastShape(object state) 
     { 
      // No need to send anything if our model hasn't changed 
      if (_modelUpdated) 
      { 
       // This is how we can access the Clients property 
       // in a static hub method or outside of the hub entirely 
       _hubContext.Clients.AllExcept(_model.LastUpdatedBy).updateShape(_model); 
       _modelUpdated = false; 
      } 
     } 
     public void UpdateShape(ShapeModel clientModel) 
     { 
      _model = clientModel; 
      _modelUpdated = true; 
     } 
     public static Broadcaster Instance 
     { 
      get 
      { 
       return _instance.Value; 
      } 
     } 
    } 

    public class MoveShapeHub : Hub 
    { 
     // Is set via the constructor on each creation 
     private Broadcaster _broadcaster; 
     public MoveShapeHub() 
      : this(Broadcaster.Instance) 
     { 
     } 
     public MoveShapeHub(Broadcaster broadcaster) 
     { 
      _broadcaster = broadcaster; 
     } 
     public void UpdateModel(ShapeModel clientModel) 
     { 
      clientModel.LastUpdatedBy = Context.ConnectionId; 
      // Update the shape model within our broadcaster 
      _broadcaster.UpdateShape(clientModel); 
     } 
    } 
    public class ShapeModel 
    { 
     // We declare Left and Top as lowercase with 
     // JsonProperty to sync the client and server models 
     [JsonProperty("left")] 
     public double Left { get; set; } 
     [JsonProperty("top")] 
     public double Top { get; set; } 
     // We don't want the client to get the "LastUpdatedBy" property 
     [JsonIgnore] 
     public string LastUpdatedBy { get; set; } 
    } 

} 

這裏是Startup.cs:

using Microsoft.Owin; 
using Owin; 

[assembly: OwinStartup(typeof(MoveShapeDemo.Startup))] 
namespace MoveShapeDemo 
{ 
    public class Startup 
    { 
     public void Configuration(IAppBuilder app) 
     { 
      // Any connection or hub wire up and configuration should go here 
      app.MapSignalR(); 
     } 
    } 
} 
+0

你可以發佈你的中心代碼? – Gjohn 2014-10-22 17:26:51

+0

我已經添加了集線器和啓動代碼。這段代碼直接來自演示,並且可以在IIS Express下運行的開發PC上正常工作。我只是無法在部署PC上的IIS 7.5下運行。 – 2014-10-22 20:39:25

+0

一旦啓動您的站點,您是否可以檢查您的集線器代理是否正在爲/ Signalr /集線器加載? – Gjohn 2014-10-23 00:07:07

回答

0

一旦你啓動你的網站,你可以檢查,看看你的集線器代理正在爲/ Signalr /集線器加載。只需點擊你的URL http:// localhost/SignalR/hubs.You應該看到SignalR生成的代理(除非你在Global.asax中關閉了它,它看起來並不像它,因爲你可以在IISExpress中找到它。

如果你可以調出樞紐代理了然後就改變你的HTML下面,從

<script src="/signalr/hubs"></script> 

        to 

    <script src="http:/localhost/signalr/hubs"></script> 

您可以瞭解更多有關SignalR here - 上是signalR一切真正好的資源

更新:

你說當在Visual Studio中運行時,IIS表示你的Move.html工作得很好。作爲Move.html的一部分,Visual Studio解決方案或項目還有什麼?你有你的樞紐的C#代碼,你有部署嗎?/signalr/hubs的使用表明Move.html和hub是同一個項目的一部分,但在你原來的查詢中,你說你剛剛移動了Move.html。您將不得不發佈整個項目並將發佈的版本移至wwwroot文件夾。對於發佈步驟看here

+0

我沒有Global.asax文件。我看到http:// lcoalhost/SignalR/hubs創建了一個不同的代理(對於另一個我試過的SignalR Web應用程序,並且在加載頁面後得到net :: Err_Connection_Reset錯誤)。所以對於這個例子沒有SignalR Proxies,沒有global.asax,它在VS 2013下運行時效果很好,但不能部署... 您發送的鏈接是基本的SignalR鏈接,我得到了示例我是試圖運行,任何指向我可以找到更多關於在IIS上成功部署它的指針? – 2014-10-23 21:05:58