Questions about the MVC SIGNALR

Source: Internet
Author: User

Just read @Learning hard [SIGNALR chapter of the ASP] topic One: ASP. SIGNALR Quick Start

Follow the steps of the blog, this is the new way of learning

However, the author's development environment and @Learning hard different, resulting in a number of small problems!

First, create a new MVC environment

Author Environment VS2013 +. NET 4.5 + MVC 4.0

The new project selects the Internet application, and in order to support SignalR, use the NuGet console to install SignalR into the project (these are system defaults and have not changed so-called authentication, but I don't know @learning hard And what the network says about identity authentication)

Install-package Microsoft.AspNet.SignalR
Then, the body that needs to be added

Create a new SIGNALR Hub (V2) class file that inherits the Hub class, creating a method that the business logic requires, in this case the main method to apply:

// Call the SendMessage method for all clients Clients.All.sendMessage (name, message);
Finally, the SignalR class is instantiated in the page to do the specific business logic

The code can refer to the "original" part given in the original text.

@section scripts{<!--referencing the SIGNALR library. -<script src="~/scripts/jquery.signalr-2.2.0.min.js"></script> <!--refer to the automatically generated SIGNALR hub (hub) script. When running, you can see the <script src= under browser source"~/signalr/hubs"></script> <script>$ (function () {//referencing the auto-generated hub agent            varChat =$.connection.serverhub; //define client SendMessage for server-side calls to display new messagesChat.client.sendMessage=function (name, message) {//add a message to a page$('#discussion'). Append ('<li><strong>'+HtmlEncode (name)+'</strong>:'+ htmlEncode (message) +'</li>');                       }; //set focus to input box$('#message'). focus (); //start connecting to the server$.connection.hub.start (). Done (function () {$ ('#sendmessage'). Click (function () {//call the Send method of the server-side hubChat.server.send ($ ('#message'). Val ()); //Empty input box information and get focus$('#message'). Val ("'). focus ();            });        });                }); //HTML-encode the displayed messagefunction HtmlEncode (value) {varEncodedvalue = $ ('<div/>'). Text (value). html (); returnEncodedvalue; }    </script>}
Other

The addition of the Controller and the view will not be said, so look at the MVC primer basically.

Here's the problem!
 while attempting to load the app. - No assembly found containing an owinstartupattribute. class  "false"in theclass in your web. config.

After running, it should be a lot of friends have such an error (may be the wrong hint in Chinese)!

Look at the error hint, in fact, directly know what the situation, Owinstartupattribute did not find!

followed by a hint of two approaches, that is, both of these practices mislead beginners!

We follow the prompts, so the search results on the Internet are:

<appSettings>    <add key= "Owin:automaticappstartup" value= "false"/></appsettings>

Hey, you really do not look, incredibly really do not error, but the following problems are bigger, because the world's business logic does not ah, how to, debugging found, browse to the business page, error:

GET http://localhost:10292/signalr/hubs 404 (not Found)
Uncaught Typeerror:cannot Read property ' client ' of undefined

Hey, what is this ...? To search the Internet a lot, and finally searched: https://github.com/SignalR/SignalR/issues/2649

The last @xiaohongt reply gives the correct method, but also the official use of SignalR steps:

Http://www.asp.net/signalr/overview/getting-started/tutorial-getting-started-with-signalr

There is one step:

6. In Solution Explorer, right-click the project, then click Add | OWIN Startup Class. Name the new class Startup and click OK. Note:if you is using Visual Studio, the OWIN Startup Class template is not being available. You can add a plain Class called Startup instead.

Then give the code (note the red):

 using   Microsoft.owin;  using   Owin; [Assembly:owinstartup ( typeof   ( Signalrchat.startup)]]  namespace   signalrchat{ public  class   Startup { public  void   Configuration (Iappbuilder app) { //  any connection or hub wire up and configuration should go here   app.        MAPSIGNALR (); }    }}

Sure enough, when this class is added, the problem is solved and the business function is implemented (remove the error code that was added to the previous web. config)!

Concluding words

Yes, yes, the problem is solved, however ... What the situation, then, there is the following conclusion:

Owin:open Web Interface for. NET

The web frameworks that support Owin are:

  • Nancy
  • SignalR
  • WebApi
  • Fubumvc
  • Simple.web
  • Duovia.http
See also: http://kb.cnblogs.com/page/509236/

Each web framework that uses the Owin component requires a startup entry class to declare the Owin component:

1. The project will automatically scan the class named startup under the root of the assembly as the entry class

2. Mark the entry class by adding a [Assembly:owinstartup (typeof(Signalrchat.startup))] tag

3. If your startup class is not under the current namespace <add key= "Owin:appstartup" value= "[NameSpace]. Startup "/>

4. Because 1th exists, if the class is named Startup and is not an entry point, you need to use <add key= "Owin:automaticappstartup" value= "false"/>

If there is any wrong place, please park friends pointed out, in case misleading new, thank you!

Element
Font
Font-family
Font-size
Font-style
Font-variant
Font-weight
Letter-spacing
Line-height
Text-decoration
Text-align
Text-indent
Text-transform
White-space
Word-spacing
Color
Background
Bg-attachment
Bg-color
Bg-image
Bg-position
Bg-repeat
Box
Width
Height
Border-top
Border-right
Border-bottom
Border-left
Margin
Padding
Max-height
Min-height
Max-width
Min-width
Outline-color
Outline-style
Outline-width
Positioning
Position
Top
Bottom
Right
Left
Float
Display
Clear
Z-index
List
List-style-image
List-style-type
List-style-position
Table
Vertical-align
Border-collapse
Border-spacing
Caption-side
Empty-cells
Table-layout
Effects
Text-shadow
-webkit-box-shadow
Border-radius
Other
Overflow
Cursor
Visibility

Questions about the MVC SIGNALR

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.