You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

readme.txt 3.0 KiB

4 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. Please see http://go.microsoft.com/fwlink/?LinkId=272764 for more information on using SignalR.
  2. Upgrading from 1.x to 2.0
  3. -------------------------
  4. Please see http://go.microsoft.com/fwlink/?LinkId=320578 for more information on how to
  5. upgrade your SignalR 1.x application to 2.0.
  6. Mapping the Hubs connection
  7. ----------------------------------------
  8. SignalR Hubs will not work without a Hub route being configured. To register the default Hubs route, create a class called Startup
  9. with the signature below and call app.MapSignalR() in your application's Configuration method. e.g.:
  10. using Microsoft.AspNet.SignalR;
  11. using Owin;
  12. namespace MyWebApplication
  13. {
  14. public class Startup
  15. {
  16. public void Configuration(IAppBuilder app)
  17. {
  18. app.MapSignalR();
  19. }
  20. }
  21. }
  22. Enabling cross-domain requests
  23. ---------------------------------------
  24. To enable CORS requests, Install-Package Microsoft.Owin.Cors and change the startup class to look like the following:
  25. using Microsoft.AspNet.SignalR;
  26. using Microsoft.Owin.Cors;
  27. using Owin;
  28. namespace MyWebApplication
  29. {
  30. public class Startup
  31. {
  32. public void Configuration(IAppBuilder app)
  33. {
  34. app.Map("/signalr", map =>
  35. {
  36. // Setup the cors middleware to run before SignalR.
  37. // By default this will allow all origins. You can
  38. // configure the set of origins and/or http verbs by
  39. // providing a cors options with a different policy.
  40. map.UseCors(CorsOptions.AllowAll);
  41. var hubConfiguration = new HubConfiguration
  42. {
  43. // You can enable JSONP by uncommenting line below.
  44. // JSONP requests are insecure but some older browsers (and some
  45. // versions of IE) require JSONP to work cross domain
  46. // EnableJSONP = true
  47. };
  48. // Run the SignalR pipeline. We're not using MapSignalR
  49. // since this branch is already runs under the "/signalr"
  50. // path.
  51. map.RunSignalR(hubConfiguration);
  52. });
  53. }
  54. }
  55. }
  56. Starting the Web server
  57. --------------------------------
  58. To start the web server, call WebApp.Start<Startup>(endpoint). You should now be able to navigate to endpoint/signalr/hubs in your browser.
  59. using System;
  60. using Microsoft.Owin.Hosting;
  61. namespace MyWebApplication
  62. {
  63. public class Program
  64. {
  65. static void Main(string[] args)
  66. {
  67. // This will *ONLY* bind to localhost, if you want to bind to all addresses
  68. // use http://*:8080 or http://+:8080 to bind to all addresses.
  69. // See http://msdn.microsoft.com/en-us/library/system.net.httplistener.aspx
  70. // for more information.
  71. using (WebApp.Start<Startup>("http://localhost:8080/"))
  72. {
  73. Console.WriteLine("Server running at http://localhost:8080/");
  74. Console.ReadLine();
  75. }
  76. }
  77. }
  78. }