Can someone please be kind enough as to tell us what is wrong with this code (The code below is happening in the same class called EntityNameBusinessLayer and we are using the C# ASP.NET MVC 5):
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Xml;
using System.Web;
using System.Web.Http;
using System.Web.UI;
using System.Web.UI.WebControls;
using Newtonsoft.Json;
using System.Globalization;
public HttpRequest Request { get; set; }
public HttpBrowserCapabilities Browser { get; set; }
public class Request { private HttpRequest request;
public Request(HttpRequest request)
{
if(request.Browser == null)
{
}
else
{
}
}
}
public HttpBrowserCapabilities Browser { get; set; }
public class ShogunTypeBusinessLayer
{
public string RetrieveUserBrowserDetails()
{
string browserSignature;
HttpBrowserCapabilities browserCapabilities = Request.Browser;
string typeBrowser = "Type : " + browserCapabilities.Type + " ";
string nameBrowser = "Name = " + browserCapabilities.Browser + " ";
string versionBrowser = "Version = " + browserCapabilities.Version + " ";
string majorVersionBrowser = "Major Version = " + browserCapabilities.MajorVersion + " ";
string minorVersionBrowser = "Minor Version = " + browserCapabilities.MinorVersion + " ";
string browserCapabilitiesBrowser = "Platform = " + browserCapabilities.Platform + " ";
string betaBrowser = "Is Beta = " + browserCapabilities.Beta + " ";
string isCrawlerBrowser = "Is Crawler = " + browserCapabilities.Crawler + " ";
string isAOLBrowser = "Is AOL = " + browserCapabilities.AOL + " ";
string isWin16Browser = "Is Win16 = " + browserCapabilities.Win16 + " ";
string isWin32Browser = "Is Win32 = " + browserCapabilities.Win32 + " ";
string supportFramesBrowserStatus ="Supports Frames = " + browserCapabilities.Frames + " ";
string supportTableBrowserStatus = "Supports Tables = " + browserCapabilities.Tables + " ";
string supportCookiesBrowserStatus = "Supports Cookies = " + browserCapabilities.Cookies + " ";
string supportVBScriptBrowserStatus = "Supports VB Script = " + browserCapabilities.VBScript + " ";
string supportJavaScriptBrowserStatus = "Supports JavaScript = " + browserCapabilities.JavaScript + " ";
string supportJavaAppletsBrowserStatus = "Supports Java Applets = " + browserCapabilities.JavaApplets + " ";
string supportActiveXControlsBrowserStatus ="Supports ActiveX Controls = " + browserCapabilities.ActiveXControls + " ";
string supportChannelDefinitionFormatBrowserStatus = "CDF = " + browserCapabilities.CDF + " ";
browserSignature = typeBrowser +
nameBrowser +
versionBrowser +
majorVersionBrowser +
minorVersionBrowser +
browserCapabilitiesBrowser +
betaBrowser +
isCrawlerBrowser +
isAOLBrowser +
isWin16Browser +
isWin32Browser +
supportFramesBrowserStatus +
supportTableBrowserStatus +
supportCookiesBrowserStatus +
supportVBScriptBrowserStatus +
supportJavaScriptBrowserStatus +
supportJavaAppletsBrowserStatus +
supportActiveXControlsBrowserStatus +
supportChannelDefinitionFormatBrowserStatus;
return browserSignature;
}
After execution we get the following exception. We are trying to save the appended string into a database to be able to determine what browser had done the insertion.
Description title: Object reference not set to an instance of an object
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 791: string browserSignature; Line 792: Line 793: HttpBrowserCapabilities browserCapabilities = Request.Browser; Line 794: Line 795: string typeBrowser = "Type : " + browserCapabilities.Type + " ";
Source File:
c:\Users\25025\Documents\Visual Studio 2012\Projects\censys_cross\censys\BusinessLayer\ShogunTypeBusinessLayer.cs Line: 793
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
censys.BusinessLayer.ShogunTypeBusinessLayer.RetrieveUserBrowserDetails() in c:\Users\25025\Documents\Visual Studio 2012\Projects\censys_cross\censys\BusinessLayer\ShogunTypeBusinessLayer.cs:793
censys.BusinessLayer.ShogunTypeBusinessLayer.AddShogunType(SHOGUN_TYPEda shogunType) in c:\Users\25025\Documents\Visual Studio 2012\Projects\censys_cross\censys\BusinessLayer\ShogunTypeBusinessLayer.cs:1124
censys.Controllers.ShogunTypeController.Create_Post() in c:\Users\25025\Documents\Visual Studio 2012\Projects\censys_cross\censys\Controllers\ShogunTypeController.cs:33
lambda_method(Closure , ControllerBase , Object[] ) +101
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +208
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
System.Web.Mvc.Async.<>c__DisplayClass42.<BeginInvokeSynchronousActionMethod>b__41() +28
System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +10
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +57
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +48
System.Web.Mvc.Async.<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33() +57
System.Web.Mvc.Async.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49() +223
System.Web.Mvc.Async.<>c__DisplayClass37.<BeginInvokeActionMethodWithFilters>b__36(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +57
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +48
System.Web.Mvc.Async.<>c__DisplayClass2a.<BeginInvokeAction>b__20() +24
System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +102
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +57
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +43
System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +14
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +57
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +47
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +25
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +47
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9651532
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
The code for some reason it's not executing.