我正在使用asp.net mvc应用程序。我在IIs上配置了这个。它以前工作过。相同的应用程序我没有进行任何设置或构建只是运行但是给出了以下错误。
此外,dll文件夹中还存在WebSystem.Web dll。我重建解决方案不工作,我清理解决方案但不工作。我注意到在\bin
文件夹中找到了Global.asax和Global.asax.cs,所以删除了但是当我从IIS运行时它会自动在\bin
文件夹下创建。
此外,我已将虚拟目录设置为应用程序文件夹100%确定。和WebSystem.Web一样,dll和namespace以及MvcApplication类在这个dll的\ bin文件夹中100%肯定。
分析器错误
说明:解析为此请求提供服务所需的资源时发生错误。请查看以下特定的解析错误详细信息并适当修改源文件。分析程序错误消息:无法加载类型' WebSystem.Web.MvcApplication'。
来源错误:
第1行:<%@ Application Codebehind =" Global.asax.cs" Inherits =" WebSystem.Web.MvcApplication"语言=" C#" %GT;
我还清理了以下(删除)此虚拟目录的所有文件。
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()
{
}
}
}
答案 0 :(得分:0)
我最近在尝试第一次运行Mvc 5应用程序时遇到了同样的问题。
此问题可能由以下任何原因引起:
确保传递给global.asax中的inherit属性的完全限定类名与为类后面的MvcApplication代码定义的相同。
But global.asax was referencing this - missing the cousant in the namespace