Hi Jacob,
You need to extend the context method to get httpcontext. For this you need to add following class file:
using Microsoft.AspNet.SignalR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
/// <summary>
/// Summary description for ExtensionClass
/// </summary>
public static class ExtensionClass
{
/// <summary>
/// Returns the <see cref="HttpContextBase"/> for this <see cref="IRequest"/>.
/// </summary>
/// <param name="request">The request</param>
public static HttpContextBase GetHttpContext(this IRequest request)
{
object httpContextBaseValue;
if (request.Environment.TryGetValue(typeof(HttpContextBase).FullName, out httpContextBaseValue))
{
return httpContextBaseValue as HttpContextBase;
}
return null;
}
public static string GetRemoteIpAddress(this IRequest request)
{
object ipAddress;
//server.LocalIpAddress
if (request.Environment.TryGetValue("server.RemoteIpAddress", out ipAddress))
{
return ipAddress as string;
}
return "";
}
}
And then you can get remote ip address and referrer url on connected as :
public override Task OnConnected()
{
string ClientReferrerURL = Context.Request.GetHttpContext().Request.ServerVariables["HTTP_REFERER"];
string RemoteIpAddress = Context.Request.GetRemoteIpAddress();
return base.OnConnected();
}
Posted On:
12-Sep-2015 02:38