0
votes

I am using asp.net mvc application. I have configured this on IIs. It was working before. Same application I haven’t did any settings or build just run but giving following error.

Also there is WebSystem.Web dll exists in dll folder. I rebuild the solution not working, I clean the solution but not working. I notice that in \bin folder Global.asax and Global.asax.cs found, so deleted but when I run from IIS it is automatically created under \bin folder.

Also I have set virtual directory to the application folder 100% sure. and WebSystem.Web is exist dll and namespace and MvcApplication class in this dll in \bin folder 100% sure.

Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message: Could not load type 'WebSystem.Web.MvcApplication'.

Source Error:

Line 1: <%@ Application Codebehind="Global.asax.cs"Inherits="WebSystem.Web.MvcApplication" Language="C#" %>

I have also clean following (deleted) all files for this virtual directory.

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files

What to do to resolved above error?

Here is my global.asax file

using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.Text;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
using System.Web.Security;
using WebSystem.Common;
using log4net;

namespace WebSystem.Web
{
   public class MvcApplication : System.Web.HttpApplication
   {
       private static readonly ILog log = LogManager.GetLogger(typeof(MvcApplication));

       protected void Application_Start()
       {
            AreaRegistration.RegisterAllAreas();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            AuthConfig.RegisterAuth();

            ModelValidatorProviders.Providers.Clear();
            ModelValidatorProviders.Providers.Add(new DataAnnotationsModelValidatorProvider());

            //Configure log4net
            string l4net = Server.MapPath("~/Log4net.config");
            log4net.Config.XmlConfigurator.ConfigureAndWatch(new  System.IO.FileInfo(l4net));
        }

        protected void Application_Error(Object sender, EventArgs e)
        {
             Exception ex = Server.GetLastError().GetBaseException();
             StringBuilder objStringBuilder = new StringBuilder();

             string ToEmail = Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["ErrorNotificationEmailID"]);
             string subject = Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["ErrorNotificationEmailSubject"]);
             string loggedInUserName = string.Empty;

             if (HttpContext.Current.Session != null)
             {
                  loggedInUserName = Convert.ToString(HttpContext.Current.Session["UserFirstName"]) + " " + Convert.ToString(HttpContext.Current.Session["UserLastName"]);
             }

             if (ex.Message.ToLower().Contains("file does not exist")) 
                return;

             System.Diagnostics.StackTrace objStackTrace = new System.Diagnostics.StackTrace(true);
             System.Diagnostics.StackFrame objStackFrame = objStackTrace.GetFrame(0);

             String SourcePath = string.Empty;

             if ((objStackFrame != null))
             {
                  SourcePath = Request.Path;
                  objStringBuilder.AppendFormat("Source File:" + Request.Path + " " + "{0}", Environment.NewLine);
             }

             // Send Mail to authorized person
             string URL = Request.Url.Scheme + "://" + Request.Url.Authority;
             string fullURLpath = Request.Url.AbsoluteUri;

             objStringBuilder = Utility.MailTemplate(Server.MapPath("~/Templates"), loggedInUserName, Server.GetLastError().Message.ToString(), ex.Message.ToString(), ex.StackTrace.ToString(), fullURLpath, URL);

            string msgData = objStringBuilder.ToString();

            if (isMailSent == false)
            {
            }

            // log.Error("App_Error", ex);
        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {
             HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName];

             if (authCookie != null)
             {
                  FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.Value);
                  GenericIdentity identity = new GenericIdentity(ticket.Name);

                  String[] MyStringArray = { "Admin", "User" };
                  GenericPrincipal principal = new GenericPrincipal(identity, MyStringArray);

                  HttpContext.Current.User = principal;
            }
        }

        /// <summary>
        /// Use Application End Request for Ajax Session Timeout Issues.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Application_EndRequest(Object sender, EventArgs e)
        {
            //If we have Session Contact Item is False then we will set Status Code=401. so, we will handle this Ajax Request 
            //Under Common.Js - > RedirectToLoginOnSessionTimeout Function.
            if (HttpContext.Current.Items["AjaxPermissionDenied"] is bool)
            {
                HttpContext.Current.Response.Clear();
                HttpContext.Current.Response.StatusCode = 401;
            }
        }

        protected void Session_Start(object sender, EventArgs e)
        {
            // event is raised each time a new session is created     
        }

        protected void Session_End()
        {
        }
    }
}
1
Please show us Global.asax.csPatrick Hofman
never heard of this namespace....WebSystem.Web ...!!SamGhatak
Because that is his project's own namespace @SamGhatakPatrick Hofman
@SamGhatak - WebSystem.Web is my application file name space. I have given it.sandip
@PatrickHofman- I have edited question and addes Global.asax.cs file. now can you tell me reason?sandip

1 Answers

0
votes

I recently had the same issue while trying to run an Mvc 5 application for its first time.

This issue can be caused by any of the following reasons:

  1. The target .Net version use by your project (in web.config) different from the version used by your application pool in IIs where the application is hosted.
  2. As in my case, accidentally changing the namespace for the MvcApplication class used by the global.asax file such that the global.asax now references a different namespace. To solve the issue in this case,

Ensure that the fully qualified classname passed to the inherit attribute in global.asax is the same as defined for the MvcApplication code behind class.

My name space was this

But global.asax was referencing this - missing the cousant in the namespace