I am able to run the Chat App using SignalR independently but after adding the files to the existing Web Application with Master Page, Chat session does not begin it stops working.I reinstalled SignalR Package many times removing it but the error still exists. Below is the code used:
ASPX:
<asp:Content ID="MyChatContent2" runat="server" ContentPlaceHolderID="ContentPlaceHolder1">
<script src="/Scripts/jquery-1.8.1.min.js" type="text/javascript"></script>
<script src="/Bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
<script src="/Scripts/jquery.signalR-1.1.2.min.js"></script>
<script src='/signalr/hubs' type="text/javascript"></script>
<script src="/ChatJs/Scripts/jquery.activity-indicator-1.0.0.min.js" type="text/javascript"></script>
<script src="/ChatJs/Scripts/jquery.chatjs.signalradapter.js" type="text/javascript"></script>
<script src="/ChatJs/Scripts/jquery.chatjs.js" type="text/javascript"></script>
<script src="/Scripts/scripts.js" type="text/javascript"></script>
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js"></script>
<link rel="stylesheet" type="text/css" href="/ChatJs/Styles/jquery.chatjs.css" />
<link rel="stylesheet" type="text/css" href="/Bootstrap/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="/Bootstrap/css/bootstrap-responsive.min.css" />
<% if (!this.IsUserAuthenticated)
{ %>
<script type="text/javascript">
function notAutho() {
aler("not autoh.....");
}
</script>
<% } %>
<% if (this.IsUserAuthenticated)
{ %>
<script type="text/javascript">
var connection = $.hubConnection("/signalr", { useDefaultPath: false });
$(function () {
debugger;
alert("chat is authenticated..");
$.chat({
user: {
Id: '<%= this.UserId %>',
Name: '<%= this.UserName %>',
ProfilePictureUrl: '/ChatJs/Images/spotlight photo.png'
},
typingText: ' is typing...',
titleText: 'Chat',
emptyRoomText: "There's no one around here. You can still open a session in another browser and chat with yourself :)",
adapter: new SignalRAdapter()
});
});
</script>
<% } %>
<%----%>
.CS:
protected void Page_Load(object sender, EventArgs e)
{
try
{
LoadChat();
}
catch
{
}
}
private void LoadChat()
{
try
{
userName.Value = Convert.ToString(Session[SessionVariables.FullName]);
empID.Value = Convert.ToString(Session[SessionVariables.emplSequ]);
if (Session[SessionVariables.isChatHandler] == null)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "chat", "joinChatwithHandler();", true);
Session[SessionVariables.isChatHandler] = "Y";
}
if (Session[SessionVariables.isUserExists] == null)
{
var existingUser = ChatCookieHelperStub.GetDbUserFromCookie(new HttpRequestWrapper(this.Request));
if (existingUser != null)
{
Session[SessionVariables.isUserExists] = "Y";
IsUserAuthenticated = true;
UserId = Convert.ToInt32(Session[SessionVariables.emplSequ]);
UserName = Convert.ToString(Session[SessionVariables.FullName]);
UserProfilePictureUrl = "/ChatJs/Images/spotlight photo.png";
}
}
}
catch
{
}
Startup.cs:
using System.Security.Cryptography;
using Microsoft.AspNet.SignalR;
using Microsoft.Owin;
using Owin;
[assembly: OwinStartup(typeof(HRMSUI.Startup))]
namespace HRMSUI
{
public static class Startup
{
public static void Configuration(IAppBuilder app)
{
try
{
CryptoConfig.AddAlgorithm(typeof(SHA256Cng), "System.Security.Cryptography.SHA256");
var hubConfiguration = new HubConfiguration();
hubConfiguration.EnableDetailedErrors = true;
hubConfiguration.EnableJavaScriptProxies = false;
app.MapSignalR("/signalr", hubConfiguration);
}
catch
{
}
}
}
}
Route.config:
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Routing;
using Microsoft.AspNet.FriendlyUrls;
namespace HRMSUI
{
public static class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
try
{
var settings = new FriendlyUrlSettings();
settings.AutoRedirectMode = RedirectMode.Permanent;
routes.EnableFriendlyUrls(settings);
}
catch
{
}
}
}
}
Web.Config:
<configuration>
<configsections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirepermission="false" />
<sectiongroup name="dotNetOpenAuth" type="DotNetOpenAuth.Configuration.DotNetOpenAuthSection, DotNetOpenAuth.Core">
<section name="messaging" type="DotNetOpenAuth.Configuration.MessagingElement, DotNetOpenAuth.Core" requirepermission="false" allowlocation="true" />
<section name="reporting" type="DotNetOpenAuth.Configuration.ReportingElement, DotNetOpenAuth.Core" requirepermission="false" allowlocation="true" />
<section name="openid" type="DotNetOpenAuth.Configuration.OpenIdElement, DotNetOpenAuth.OpenId" requirepermission="false" allowlocation="true" />
<section name="oauth" type="DotNetOpenAuth.Configuration.OAuthElement, DotNetOpenAuth.OAuth" requirepermission="false" allowlocation="true" />
</sectiongroup>
</configsections>
<appsettings>
<add key="owin:AppStartup" value="HRMSUI.Startup" />
</appsettings>
<system.web>
<compilation debug="true" targetframework="4.5" />
<httpruntime targetframework="4.5" />
<pages controlrenderingcompatibilityversion="4.0">
<namespaces>
<add namespace="System.Web.Optimization" />
</namespaces>
<controls>
<add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagprefix="webopt" />
<add tagprefix="ajaxToolkit" assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" /></controls></pages>
<authentication mode="Forms">
<forms loginUrl="~/Account/Login.aspx" timeout="2880" />
</authentication>
<sessionstate mode="InProc" customprovider="DefaultSessionProvider">
<providers>
<add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionstringname="DefaultConnection" />
</providers>
</sessionstate>
</system.web>
<runtime>
<assemblybinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentassembly>
<assemblyidentity name="DotNetOpenAuth.Core" publickeytoken="2780ccd10d57b246" />
<bindingredirect oldversion="0.0.0.0-4.3.0.0" newversion="4.3.0.0" />
</dependentassembly>
<dependentassembly>
<assemblyidentity name="DotNetOpenAuth.AspNet" publickeytoken="2780ccd10d57b246" />
<bindingredirect oldversion="0.0.0.0-4.3.0.0" newversion="4.3.0.0" />
</dependentassembly>
<dependentassembly>
<assemblyidentity name="Microsoft.Owin" publickeytoken="31bf3856ad364e35" culture="neutral" />
<bindingredirect oldversion="0.0.0.0-2.1.0.0" newversion="2.1.0.0" />
</dependentassembly>
<dependentassembly>
<assemblyidentity name="Microsoft.AspNet.SignalR.Core" publickeytoken="31bf3856ad364e35" culture="neutral" />
<bindingredirect oldversion="0.0.0.0-2.0.3.0" newversion="2.0.3.0" />
</dependentassembly>
<dependentassembly>
<assemblyidentity name="WebGrease" publickeytoken="31bf3856ad364e35" culture="neutral" />
<bindingredirect oldversion="0.0.0.0-1.5.2.14234" newversion="1.5.2.14234" />
</dependentassembly>
<dependentassembly>
<assemblyidentity name="HtmlAgilityPack" publickeytoken="bd319b19eaf3b43a" culture="neutral" />
<bindingredirect oldversion="0.0.0.0-1.4.0.0" newversion="1.4.0.0" />
</dependentassembly>
<dependentassembly>
<assemblyidentity name="Microsoft.WindowsAzure.Storage" publickeytoken="31bf3856ad364e35" culture="neutral" />
<bindingredirect oldversion="0.0.0.0-2.1.0.4" newversion="2.1.0.4" />
</dependentassembly>
<dependentassembly>
<assemblyidentity name="Microsoft.Owin.Security" publickeytoken="31bf3856ad364e35" culture="neutral" />
<bindingredirect oldversion="0.0.0.0-2.1.0.0" newversion="2.1.0.0" />
</dependentassembly>
</assemblybinding>
</runtime>
<entityframework>
<defaultconnectionfactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
</entityframework>
<system.webserver>
<modules runallmanagedmodulesforallrequests="true">
</modules>
</system.webserver>
</configuration>
I get the below error when i try running the Project:
Error Caught in
Error in: http:
Main Exception: System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.Owin.Mapping.MapMiddleware.<invoke>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.Owin.Host.SystemWeb.Infrastructure.ErrorState.Rethrow()
at Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.StageAsyncResult.End(IAsyncResult ar)
at Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.EndFinalWork(IAsyncResult ar)
at System.Web.HttpApplication.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
Base Exception : System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.Owin.Mapping.MapMiddleware.<invoke>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.Owin.Host.SystemWeb.Infrastructure.ErrorState.Rethrow()
at Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.StageAsyncResult.End(IAsyncResult ar)
at Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.EndFinalWork(IAsyncResult ar)
at System.Web.HttpApplication.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
Please help me with the solution.
[Edit member="Tadit"]
Corrected formatting issues.
Added
pre
tags.
[/Edit]