locked
ASP.NET WebForm(C#) with SignalR only can run on IE11, use Google Chrome cannot connection suceessfully RRS feed

  • Question

  • User1497005810 posted

    Complete Source Code:https://onedrive.live.com/embed?cid=FBEB6373D9321A7F&resid=FBEB6373D9321A7F%21691613&authkey=AFmObvYCI95xn2I

    This solution is consist of three projects:

    (1)SignalRServer:C# project, user persistence connection's SignalRServer. The SignalRServer is the bridge bewteeen Window Form and WebForm.

    (2)SignalRClientWinForm:SignalR Client,Window Form Project with C#, first input the user name and then click login button(send to SignalRServer and insert a user info to User List), and then input the word you want to say and click send button. The SignalRServer will broadcast to all user.

    (3)SignalRClientWebForm:SignalR Client,ASP.NET Web Form with C#, first input the user name and then click login button(send to SignalRServer and insert a user info to User List), and then input the word you want to say and click send button. The SignalRServer will broadcast to all user.

    The connection of Window Form and SignalRServer has no problem. They can communicate each other. The connection of Web Form and SignalRServer also has no problem on IE11. But if I use Google Chrome(version 58.0.3029.110 (64-bit)) to run the Web Form, the connection from Web Form(Javascript) to SignalRServer will be fail.

    I Show my JavaScript of Web Form Client as below. I think the problem is at connection.start(), but I am not sure that whether add the OnError function (like) can get the error message in the connection.start?

    Does somebody know how to solve this problem? Because my projects in this solution use .net framework 4.0 and then want to integrate with other .net framework project. So I cannot upgrade to .net framework 4.5.

    	<script type="text/javascript">
    
    		var bUseLocal = true;
    		var ConnectionID = "";
    
    		$(function () {
    
    			if (bUseLocal) {
    				connection = $.connection("http://localhost:20926/realtime/echo");
    			}
    			else {
    				connection = $.connection("http://192.168.1.1/SignalRServer/realtime/echo");
    			}
    
    			connection.logging = true;
    
    			connection.received(function (data) {
    				var messageBase = data;
    				if (messageBase.CommandName == "RequestInfo") {
    
    					ConnectionID = messageBase.ConnectionID;
    				}
    				else if (messageBase.CommandName == "TalkWord") {
    					var TextAll = document.getElementById('TextAll');
    					TextAll.value += messageBase.Word + "\r\n";
    				}
    			});
    
    			connection.start().done(function () {
    				alert("connection success");
    
    				$("#ButtonLogin").click(function () {
    					var TextUserName = document.getElementById('TextUserName');
    					var LoginData =
    					{
    						CommandName: 'LoginData',
    						ConnectionID: ConnectionID,
    						UserName: TextUserName.value
    					};
    					var str = JSON.stringify(LoginData);
    
    					alert(str);
    					connection.send(str);
    				});
    
    				$("#ButtonSend").click(function () {
    					var TextUserName = document.getElementById('TextUserName');
    					var TextSend = document.getElementById('TextSend');
    					var word = TextUserName.value + ":" + TextSend.value;
    
    					var TalkWord =
    					{
    						CommandName: 'TalkWord',
    						Word: word
    					};
    
    					var str = JSON.stringify(TalkWord);
    					connection.send(str);
    				});
    			});
    		});
    
    	</script>

    Friday, May 26, 2017 1:55 AM

Answers

  • User1967761114 posted

    Hi akira32,

    I reproduced your project and I found the issue was  occurred by cross-domain.

    You could enable cross-domain such like the following code on SignlaR server, then it works well on chrome.

    //Project: SignalRServer
    //File:Global.asax.cs
    RouteTable.Routes.MapConnection<EchoConnection>("EchoConnection", "/realtime/echo", new Microsoft.AspNet.SignalR.ConnectionConfiguration()
    {
        EnableCrossDomain = true
    });
    

    If you have any other questions, please feel free to contact me any time.

    Best Regards

    Even



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 29, 2017 2:14 AM

All replies

  • User1967761114 posted

    Hi akira32,

    I reproduced your project and I found the issue was  occurred by cross-domain.

    You could enable cross-domain such like the following code on SignlaR server, then it works well on chrome.

    //Project: SignalRServer
    //File:Global.asax.cs
    RouteTable.Routes.MapConnection<EchoConnection>("EchoConnection", "/realtime/echo", new Microsoft.AspNet.SignalR.ConnectionConfiguration()
    {
        EnableCrossDomain = true
    });
    

    If you have any other questions, please feel free to contact me any time.

    Best Regards

    Even



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 29, 2017 2:14 AM
  • User1497005810 posted

    Thank you,EvenMa. I had solved this problem. Thanks!

    Tuesday, May 30, 2017 4:59 AM