locked
Windows Form as SignalR Sever, WebForm Client as SignalR Client. How to set EnableCrossDomain in .net framework 4.5 and SignalR2? RRS feed

  • Question

  • User1497005810 posted

    I try to connect ASP.NET WebForm as SignalR Server and Windows Form as SignalR Client(.net framework 4.0. And then I set EnableCrossDomain variable, so I can use google chrome without problem.

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

    But I upgrade the projects to .net framework 4.5 and change the SignalR Server to Windows Form Client. I add  Startup.cs to Windows Form Project.

    But I do not know how to add EnableCrossDomain. Does somebody know how to add EnableCrossDomain to .net framework 4.5 Windows Form?

    I also have another problem. I cannot enable breakpoint in ASP.NET WebForm javascript in aspx. My breakpoint seem to be invalid(no stop).

    using Microsoft.Owin;
    using Owin;
    
    [assembly: OwinStartup(typeof(WebApplicationHistory.Startup))]
    namespace WebApplicationHistory
    {
        public class Startup
        {
            public void Configuration(IAppBuilder app)
            {            
                app.MapSignalR<EchoConnection>("/realtime/echo");
            }
        }
    }
    Tuesday, June 13, 2017 6:41 AM

Answers

  • User1967761114 posted

    Hi akira32,

    According to your description, you could use cors to enable cross domain.

    (1) Install the package of “Microsoft.Owin.Cors” by Nuget.

    (2) Then in Startup.cs:

    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            app.UseCors(CorsOptions.AllowAll);
            app.MapSignalR<EchoConnection>("/realtime/echo");
        }
    }

    I also have another problem. I cannot enable breakpoint in ASP.NET WebForm javascript in aspx. My breakpoint seem to be invalid(no stop).

    If you couldn’t use breakpoint to debug javascript, I recommend that you could use the developer tool of browser to debug javascript, you could refer to the following link.

    https://msdn.microsoft.com/en-us/library/gg699336(v=vs.85).aspx

    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
    Wednesday, June 14, 2017 7:38 AM

All replies

  • User1967761114 posted

    Hi akira32,

    According to your description, you could use cors to enable cross domain.

    (1) Install the package of “Microsoft.Owin.Cors” by Nuget.

    (2) Then in Startup.cs:

    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            app.UseCors(CorsOptions.AllowAll);
            app.MapSignalR<EchoConnection>("/realtime/echo");
        }
    }

    I also have another problem. I cannot enable breakpoint in ASP.NET WebForm javascript in aspx. My breakpoint seem to be invalid(no stop).

    If you couldn’t use breakpoint to debug javascript, I recommend that you could use the developer tool of browser to debug javascript, you could refer to the following link.

    https://msdn.microsoft.com/en-us/library/gg699336(v=vs.85).aspx

    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
    Wednesday, June 14, 2017 7:38 AM
  • User1497005810 posted

    Thank you,EvenMa! I successfully run windows form as SignalR Server and WebForm as SignalR Client. In the windows 10 google chrome, there is no problem. But therei is an error in iOS and Android platform. The error is "Error during negotiation request".  My connection is persistence connection. I also add EnableJSONP = true into MapSignalR function, but still does not work. Does somebody know the persistence connection in the clients of iOS and Android will consider somethings?

    Windows Form

            private void buttonStart_Click(object sender, EventArgs e)
            {
                string szIP = textBoxServerIP.Text;
    	    string fullIP = "";
    
    
                try
                {
    		fullIP = @"http://" + szIP + @":9000";
    
    		SignalR = WebApp.Start(fullIP);
    				
    		textBoxAll.Text += "Start successfully!IP=" + fullIP + "\r\n";
                }
                catch (Exception ex)
                {
                    textBoxAll.Text += "Start unsccessfully!ex=" + ex.Message + "\r\n";
    
                    Debug.WriteLine("Exception = " + ex.ToString());
                }
            }

    StartUp.cs

    using Microsoft.Owin;
    using Microsoft.Owin.Cors;
    using Owin;
    
    [assembly: OwinStartup(typeof(WebApplicationHistory.Startup))]
    namespace WebApplicationHistory
    {
        public class Startup
        {
            public void Configuration(IAppBuilder app)
            {
    		app.UseCors(CorsOptions.AllowAll);
    
    		var config = new Microsoft.AspNet.SignalR.ConnectionConfiguration();
    		config.EnableJSONP = true;
    			
    		app.MapSignalR<EchoConnection>("/realtime/echo", config);
            }
        }
    }

    Windows Form (SignalR Server) ,Start Persitence Connection

    private IDisposable SignalR { get; set; }

    private void buttonStart_Click(object sender, EventArgs e) { string szIP = textBoxServerIP.Text; string fullIP = ""; if (szIP == "" && bLocal == false) { MessageBox.Show("Please input SignalR Server IP"); return; } try { if (bLocal == true) { fullIP = ServerURI; } else { fullIP = @"http://" + szIP + @":9000"; } SignalR = WebApp.Start(fullIP); textBoxAll.Text += "Start successfully!IP=" + fullIP + "\r\n"; } catch (Exception ex) { textBoxAll.Text += "Start unsccessfully!ex=" + ex.Message + "\r\n"; Debug.WriteLine("Exception = " + ex.ToString()); } }

    There is a exeception at "SignalR = WebApp.Start(fullIP);". The exception error message as below picture:

    Does somebody know how to I set the windows form (signalr server)'s IP address for other client to connect?

    引動過程的目標傳回例外狀況=target invocation exception

    存取被拒=Access denied

    The problem of "target invocation exception" was solved by me using Admin opening Visual Studio 2017.

    I have a confuse the WebApp.Start(url) can set the url as local computer ip? And then other devices can connect to the url of WebApp.Start by SignalR?

    Friday, June 16, 2017 7:02 AM
  • User1497005810 posted

    I had solved this problem. The deployment for self hosting signalr server is that run the exe by admin privilege. 192.168.1.10 is local computer IP. And other devices can connect the url by signalr.

    fullIP  = @"http://" + "192.168.1.10" + @":9001" SignalR = WebApp.Start(fullIP);

    Monday, June 19, 2017 6:33 AM