SignalR.Net Client - Unexpected character encountered during parsing

I am trying to configure a .NET client to send messages to my signalR hub from my service level. I follow this guide: http://www.asp.net/signalr/overview/signalr-20/hubs-api/hubs-api-guide-net-client#callserver

This is what I have:

        _hubConnection = new HubConnection(_baseUrl); // "http://localhost:3806"
        _hubProxy = _hubConnection.CreateHubProxy("AppHub");
        _hubConnection.Start().Wait();

The hub lives inside the same project - this is an MVC application with forms authentication.

I can never get through the .Wait () call, it always throws an error with the following:

Message=Unexpected character encountered while parsing value: <. Path '', line 0, position 0.
       Source=Newtonsoft.Json

More trace:

Newtonsoft.Json.JsonConvert.DeserializeObject [T] ( )              Microsoft.AspNet.SignalR.Client.Transports.TransportHelper.b_1 (String )              Microsoft.AspNet.SignalR.TaskAsyncHelper. < > c_DisplayClass19 2.<Then>b__17(Task 1 )              Microsoft.AspNet.SignalR.TaskAsyncHelper.TaskRunners 2.<>c__DisplayClass3a.<RunTask>b__39(Task 1 )

AppHub:

public class AppHub : Hub {

?

+4
3

, , - HubConnection, . , SignalR : http://www.asp.net/signalr/overview/signalr-20/security/hub-authorization

class Program
    {
    static void Main(string[] args)
    {
        var connection = new HubConnection("http://www.contoso.com/");
        Cookie returnedCookie;

        Console.Write("Enter user name: ");
        string username = Console.ReadLine();

        Console.Write("Enter password: ");
        string password = Console.ReadLine();

        var authResult = AuthenticateUser(username, password, out returnedCookie);

        if (authResult)
        {
            connection.CookieContainer = new CookieContainer();
            connection.CookieContainer.Add(returnedCookie);
            Console.WriteLine("Welcome " + username);
        }
        else
        {
            Console.WriteLine("Login failed");
        }    
    }

    private static bool AuthenticateUser(string user, string password, out Cookie authCookie)
    {
        var request = WebRequest.Create("https://www.contoso.com/RemoteLogin") as HttpWebRequest;
        request.Method = "POST";
        request.ContentType = "application/x-www-form-urlencoded";
        request.CookieContainer = new CookieContainer();

        var authCredentials = "UserName=" + user + "&Password=" + password;
        byte[] bytes = System.Text.Encoding.UTF8.GetBytes(authCredentials);
        request.ContentLength = bytes.Length;
        using (var requestStream = request.GetRequestStream())
        {
            requestStream.Write(bytes, 0, bytes.Length);
        }

        using (var response = request.GetResponse() as HttpWebResponse)
        {
            authCookie = response.Cookies[FormsAuthentication.FormsCookieName];
        }

        if (authCookie != null)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
}

RemoteLogin:

using System;
using System.Web.Security;

namespace SignalRWithConsoleChat
{
    public partial class RemoteLogin : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string username = Request["UserName"];
            string password = Request["Password"];
            bool result = Membership.ValidateUser(username, password);
            if (result)
            {
                FormsAuthentication.SetAuthCookie(username, false);
            }
        }
    }
}
+9

Signalr , :

<location path="signalr">
  <system.web>
    <authorization>
      <allow users="*" />
    </authorization>
  </system.web>
</location>
+2

- , - HTML- -! !

0

All Articles