6

ユーザーがクリックして何かに入札できるボタンがあります。入札ごとに、最新の入札を他のすべてのクライアントにブロードキャストします。それが私がSignalRを使用している理由です。

ここで、ユーザーはアクティブなクレジットを持っている必要があります。クレジットがない場合は、どこかにリダイレクトしたいと思います。

より明白なアプローチは私を失敗させるので、どんな提案も歓迎します。

//Does the user have credits to spend?
if (user.LanceCreditBalance >= 1)
{
    //populate the "ar" object and send it out to everybody.
    var result = Json.Encode(ar);
    Clients.addMessage(result);
}
else
{
    //And this isn't working as expected. Doesn't redirect
    //And causes a 302 error when viewing the Firebug console in Firefox.
    HttpContext.Current.Response.Redirect(@"http://www.google.com");
}

上記のコードはすべて、SignalR.Hubクラスから継承するChatクラス内にあります。

4

1 に答える 1

12

サーバ:

if(user.LanceCreditBalance >= 1)
{
    var result = Json.Encode(ar);
    // send Message to all clients
    Clients.addMessage(result);
}
else
{
    // Invoke a js-Function only on the current client
    Caller.redirectMe("http://www.google.com");
}

クライアント:

$(function () {
    var chat = $.connection.chat;

    chat.addMessage = function(message) {
        // do something
    };

    // function the server can invoke
    chat.redirectMe = function(target) {
        window.location = target;
    };

    $.connection.hub.start();
});
于 2011-09-13T16:14:24.880 に答える