Onl*_*ere 4 c# redirect asp.net-mvc-3 signalr
我有一个按钮,用户可以点击以对某些内容出价.每次出价都会向每个其他客户广播最新出价.这就是我使用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");
}
Run Code Online (Sandbox Code Playgroud)
上面的代码都在Chat类中,它继承自SignalR.Hub类.
Sim*_*ser 11
服务器:
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");
}
Run Code Online (Sandbox Code Playgroud)
客户:
$(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();
});
Run Code Online (Sandbox Code Playgroud)