2016-04-07 114 views
0

我正在使用asp.net mvc應用程序。我已經在IIs上配置了這個。它在工作之前。相同的應用程序我沒有做任何設置或建立只是運行,但給以下錯誤。無法加載程序集/類型?

另外還有WebSystem.Web dll存在於dll文件夾中。我重建解決方案不工作,我清理解決方案,但不工作。我注意到,在\bin文件夾中找到Global.asax和Global.asax.cs,所以刪除了,但是當我從IIS運行它時,它會自動創建在\bin文件夾下。

此外,我已經100%確定將虛擬目錄設置爲應用程序文件夾。和WebSystem.Web是存在的DLL和命名空間和MvcApplication類在這個DLL在\ bin文件夾100%肯定。

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#" %>

我也清除下列(刪除)此虛擬目錄的所有文件。

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

如何解決上述錯誤?

這裏是我的Global.asax文件

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

請告訴我們的Global.asax.cs –

+2

從來沒有聽說過這個名字空間....'WebSystem.Web'的。 .. !! – SamGhatak

+0

因爲那是*他的項目自己的*命名空間@SamGhatak –

回答

0

最近我有同樣的問題,而試圖運行的第一次一個MVC 5應用程序。

  1. 您的項目(在web.config中)目標.NET版本使用來自不同 非法入境者中,其中使用的應用程序池的版本:

    這個問題可以通過以下任何一種原因造成的應用程序 託管。

  2. 與我一樣,意外地更改了global.asax文件使用的MvcApplication類的名稱空間,以便global.asax現在引用不同的名稱空間。爲了解決這個問題,在這種情況下,

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

相關問題