你好我想signalr聊天这里是我的指数Signalr聊天记录用户名
<script>
$(function() {
var currentMember= @Html.Raw(@ViewBag.Name);
// Reference the auto-generated proxy for the hub.
var chat = $.connection.chatHub;
// Create a function that the hub can call back to display messages.
chat.client.addNewMessageToPage = function (name, message) {
// Add the message to the page.
$('#discussion').append('<li><strong>' + htmlEncode(name)
+ '</strong>: ' + htmlEncode(message) + '</li>');
};
// Get the user name and store it to prepend to messages.
$('#displayname').val(prompt('Enter your name:', ''));
// Set initial focus to message input box.
$('#message').focus();
// Start the connection.
$.connection.hub.start().done(function() {
$('#sendmessage').click(function() {
// Call the Send method on the hub.
chat.server.send($('#displayname').val(), $('#message').val());
// Clear text box and reset focus for next comment.
$('#message').val('').focus();
});
});
});
// This optional function html-encodes messages for display in the page.
function htmlEncode(value) {
var encodedValue = $('<div />').text(value).html();
return encodedValue;
}
</script>
,而不是这一行
$('#displayname').val(prompt('Enter your name:', ''));
我尝试了这些
$('#displayname').val("@HttpContext.Current.User.Identity.Name");
$('#displayname').val(currentMember);
的获得登录会员名
但这些没有奏效。那么我怎样才能获得我的登录成员名?
您登录了吗? HttpContext.Current是否为空?发生什么事 ? – Shyju
是的我登录但我不知道httpContext.current null或不,但我可以看到和错误说未捕获的ReferenceError:GearedSkull没有定义。 Gearedskull iste用户 – furkan
我做了一个警报,我的ViewBag.name和“@ HttpContext.Current.User.Identity.Name”很好用,但是这个signalr不能得到名字 – furkan