私はSignalRを使用していましたが、WebアプリケーションのインデックスページはSignalRでうまくいきましたが、このプッシュ通知システムを使用して詳細ページを作成すると、 SignalRは詳細ページでクライアントのメソッドを呼び出していません。ASP .Net SignalRがクライアントのメソッドを呼び出さない
はここでカミソリを使用して、私の詳細ページのコードです:
<h2>last bidders</h2>
<table class="table-info" style="width: 500px;">
<thead>
<th>bidder</th>
<th>price</th>
<th>time</th>
<th>state</th>
</thead>
@for (int i = 0; i < 10; i++)
{
if (i < ViewBag.count) // Bidder exists
{
<tr>
<td id="@Html.Raw("bidder" + i)">@ViewBag.bidders[i]</td>
<td id="@Html.Raw("price" + i)">@ViewBag.prices[i]</td>
<td id="@Html.Raw("time" + i)">@ViewBag.times[i]</td>
<td id="@Html.Raw("state" + i)">@ViewBag.states[i]</td>
</tr>
}
else // No bidder - fill with blank
{
<tr>
<td id="@Html.Raw("bidder" + i)"> </td>
<td id="@Html.Raw("price" + i)"> </td>
<td id="@Html.Raw("time" + i)"> </td>
<td id="@Html.Raw("state" + i)"> </td>
</tr>
}
}
</table>
<input type="hidden" id="IDAuction" value="@ViewBag.IDAuction" />
@section scripts {
<script src="~/Scripts/jquery.signalR-2.2.0.min.js"></script>
<script src="~/signalr/hubs"></script>
<script>
$(function() {
var my_hub = $.connection.myHub;
my_hub.client.auctionDetailsUpdate = function (IDAuction, newBidder, newPrice, newTime, newState) {
alert("auctionDetailsUpdate()");
var x = document.getElementById("IDAuction").value;
alert('1');
if (x == IDAuction) {
alert('2');
moveRowsDown();
alert('3');
document.getElementById("time0").innerHTML = newTime;
document.getElementById("price0").innerHTML = newPrice;
document.getElementById("bidder0").innerHTML = newBidder;
document.getElementById("state0").innerHTML = newState;
alert('4');
}
};
// Client register on MyHub
$.connection.hub.start().done(function() {
$(document).ready(function() {
//my_hub.server.registerConId($("#clientEmail").val());
});
});
});
function moveRowsDown() {
alert('moverowsdown')
for (var i = 9; i > 0; i--) {
document.getElementById("time" + i).innerHTML = document.getElementById("time" + (i - 1)).innerHTML;
document.getElementById("price" + i).innerHTML = document.getElementById("price" + (i - 1)).innerHTML;
document.getElementById("bidder" + i).innerHTML = document.getElementById("bidder" + (i - 1)).innerHTML;
document.getElementById("state" + i).innerHTML = document.getElementById("state" + (i - 1)).innerHTML;
}
}
</script>
ここに私のインデックスページがあります(私は役に立たない情報で私の質問を埋めるためにない試みた、SignalRにのみ関連するコードを入れています)コードで:
@section scripts {
<script src="~/Scripts/jquery.signalR-2.2.0.min.js"></script>
<script src="~/signalr/hubs"></script>
<script>
$(function() {
var my_hub = $.connection.myHub;
// Server reply on bid attempt
my_hub.client.clientBidsUpdate = function (IDAuction, newState, newDuration, newLastBidder, newPrice, warningNoTokens) {
var clientEmail = $("#" + "email" + IDAuction).val();
$("#" + "state" + IDAuction).text(newState);
$("#" + "time" + IDAuction).text(newDuration);
$("#" + "price" + IDAuction).text(newPrice);
// Unsuccessful bid
if (warningNoTokens == "true") {
if (newLastBidder == clientEmail) {
alert("Not enough tokens to place bigger bid. Please buy some tokens!");
}
// Succesful bid
} else {
$("#" + "lastbidder" + IDAuction).text(newLastBidder);
$("#" + "spanPrice" + IDAuction).addClass("glyphicon glyphicon-arrow-up");
$("#" + "spanPrice2" + IDAuction).addClass("glyphicon glyphicon-arrow-up");
}
};
// Increase previous bidder token number - someone has bigger bid
my_hub.client.setTokenNumber = function (clientSelector, tokenNumber, clientAlertSelector) {
document.getElementById(clientSelector).innerHTML = tokenNumber;
document.getElementById(clientAlertSelector).style.display = "inline-block";
}
// Timer Update method // each 1 second
my_hub.client.timerUpdate = function (IDAuction, newState, newDuration, newLastBidder, newPrice) {
$("#" + "state" + IDAuction).text(newState);
$("#" + "time" + IDAuction).text(newDuration);
$("#" + "lastbidder" + IDAuction).text(newLastBidder);
$("#" + "price" + IDAuction).text(newPrice);
// Disable auction on client side
if (newState == "Sold" || newState == "Expired") {
if (newState == "Sold") {
$("#" + "btn" + IDAuction).html("Sold");
$("#" + "btn" + IDAuction).removeClass("btn-warning btn").addClass("btn-info btn");
$("#" + "btn" + IDAuction).css("background-color", "blueviolet");
$("#" + "btn" + IDAuction).css("color", "white");
$("#" + "state" + IDAuction).css("color", "blueviolet");
$("#" + "spanLastBidder" + IDAuction).removeClass("glyphicon glyphicon-user").addClass("glyphicon glyphicon-ok");
$("#" + "picture" + IDAuction).css("-webkit-filter", "blur(8px)").css("filter", "blur(8px)");
$("#" + "btn" + IDAuction).prop("disabled", true);
}
else if (newState == "Expired") {
$("#" + "btn" + IDAuction).html("Expired");
$("#" + "btn" + IDAuction).removeClass("btn-warning btn").addClass("btn-default btn");
$("#" + "state" + IDAuction).css("color", "rgb(255, 54, 40)");
$("#" + "spanLastBidder" + IDAuction).removeClass("glyphicon glyphicon-user").addClass("glyphicon glyphicon-remove");
$("#" + "picture" + IDAuction).css("-webkit-filter", "blur(8px)").css("filter", "blur(8px)");
$("#" + "btn" + IDAuction).prop("disabled", true);
$("#" + "btn" + IDAuction).css("background-color", "rgb(255, 54, 40)");
}
}
$("#" + "spanPrice" + IDAuction).removeClass("glyphicon glyphicon-arrow-up");
$("#" + "spanPrice2" + IDAuction).removeClass("glyphicon glyphicon-arrow-up");
var clientEmail = document.getElementById("clientEmail").value;
var clientEmailReplaced = clientEmail.replace("@@", "_");
document.getElementById("alertToken" + clientEmailReplaced).style.display = "none";
};
// Client sends bid to Server
$.connection.hub.start().done(function() {
$('.btnBid').click(function (event) {
var idBtnJquery = $(event.target).attr('id');
var IDAuc = idBtnJquery.substring(3, idBtnJquery.length);
var clientEmail = $("#" + "email" + IDAuc).val();
my_hub.server.send(IDAuc, clientEmail);
});
});
// Client register on MyHub
$.connection.hub.start().done(function() {
$(document).ready(function() {
my_hub.server.registerConId($("#clientEmail").val());
});
});
});
function htmlEncode(value) {
var encodedValue = $('<div />').text(value).html();
return encodedValue;
}
// Variables
var toolbarVisible = false;
// Search - Menu toolbar preview
$("#showHideBtn").click(function() {
$("#menuSearchToolbar").slideToggle("slow", "swing");
if (toolbarVisible == true) {
toolbarVisible = false;
$("#showHideBtn").removeClass("glyphicon glyphicon-chevron-up").addClass("glyphicon glyphicon-chevron-down");
} else {
toolbarVisible = true;
$("#showHideBtn").removeClass("glyphicon glyphicon-chevron-down").addClass("glyphicon glyphicon-chevron-up");
}
});
</script>
}
ここに私のハブサーバークラスは
0123ですnamespace IEP_Projekat.Hubs
{
public static class mutex
{
public static string lockObject = "MutEx";
}
public class MyHub : Hub
{
private static Dictionary<string, string> hashUsersConnIds = new Dictionary<string, string>(512);
public void Send(long IDAuc, string lastBidderEmail)
{
lock (mutex.lockObject)
{
if ((productNewPrice <= user.TokenNumber))
{
if (previousBidderID != null)
{
if (hashUsersConnIds.ContainsKey(previous.Email))
{
Clients.Client(hashUsersConnIds[previous.Email]).setTokenNumber(clientSelector, newTokenCount, clientAlertSelector);
}
if (previous.Email != lastBidderEmail && hashUsersConnIds.ContainsKey(lastBidderEmail)) {
Clients.Client(hashUsersConnIds[lastBidderEmail]).setTokenNumber(clientSelector, newBidderCount, clientAlertSelector);
}
}
else
{
if (hashUsersConnIds.ContainsKey(lastBidderEmail))
{
Clients.Client(hashUsersConnIds[lastBidderEmail]).setTokenNumber(clientSelector, newBidderCount, clientAlertSelector);
}
}
Clients.All.clientBidsUpdate(IDAuc, auction.state, remainingToEnd, lastBidderEmail, auction.price + auction.increment, "false");
Clients.All.auctionDetailsUpdate(IDAuc, lastBidderEmail, auction.price + auction.increment, newBid.bidTime, "Open");
return;
}
else if (auction.lastbidder == user.Email)
{
if (user.TokenNumber > 0) // can place next bid
{
if (hashUsersConnIds.ContainsKey(lastBidderEmail))
{
Clients.Client(hashUsersConnIds[lastBidderEmail]).setTokenNumber(clientSelector, user.TokenNumber, clientAlertSelector);
}
Clients.All.clientBidsUpdate(IDAuc, auction.state, remainingToEnd, lastBidderEmail, auction.price + auction.increment, "false");
Clients.All.auctionDetailsUpdate(IDAuc, lastBidderEmail, auction.price + auction.increment, newBid.bidTime, "Open");
return;
}
}
Clients.All.clientBidsUpdate(IDAuc, auction.state, remaining, lastBidderEmail, auction.price + auction.increment, "true");
}
}
// Registring client
public void registerConId(string email)
{
hashUsersConnIds[email] = Context.ConnectionId;
}
}
public class MyRegistry : Registry
{
public MyRegistry()
{
Schedule(() =>
{
lock (mutex.lockObject)
{
var hubContext = GlobalHost.ConnectionManager.GetHubContext<MyHub>();
foreach (var auction in auctionsList)
{
if (now >= end)
{
if (edited.increment == 0)
{
hubContext.Clients.All.timerUpdate(auction.IDAuc, edited.state, newDurationExpired, " - ", edited.price);
}
else
{
hubContext.Clients.All.timerUpdate(auction.IDAuc, edited.state, newDurationSold, edited.lastbidder, soldPrice);
hubContext.Clients.All.auctionDetailsUpdate(auction.IDAuc, edited.lastbidder, soldPrice, newDurationSold, "Sold");
}
}
hubContext.Clients.All.timerUpdate(auction.IDAuc, auction.state, newDuration, auction.lastbidder, actualPrice);
}
}
}).ToRunNow().AndEvery(1).Seconds();
}
}
}
私のサーバーロジックは次のとおりです。私はハブクラスとしてMyHub.csを、タイマーとしてRegistryを使用しています。私はデータベースアクセスのコードといくつかの計算を掃除しました。その部分は問題ありません。私は350行のコードを書くことを避けたいので、このSignalRの相互作用に重要なコードを残しました。 Webアプリケーションのデバッグ中に、私はそれがすべての罰金、および他の方法のSignalR法の作品と言うが、私は私の詳細から任意のアラートを得ることはありません、Clients.All.auctionDetailsUpdate(...)での問題を持っている
何らかの理由でauctionDetailsUdate()メソッドに指定されたページがハブから呼び出されていません。