Создание обработчика Application_Error в файле Global.asax, получающем ошибку парсера

Я пытаюсь добавить метод Application_Error в файл Global.asax, но получаю ошибку парсера:

Ошибка сервера в приложении '/' Описание ошибки синтаксического анализатора: Произошла ошибка при синтаксическом анализе ресурса, необходимого для обслуживания этого запроса. Ознакомьтесь со следующими конкретными сведениями об ошибках синтаксического анализа и соответствующим образом измените исходный файл.

Сообщение об ошибке синтаксического анализатора: содержимое файла приложения недопустимо.

Я не понимаю, почему этот метод не работает. Любая помощь приветствуется, спасибо!

<%@Application Language='C#' Inherits="Sitecore.Web.Application" %>

using System.Configuration;

protection void Application_Error(object sender, EventArgs e)
{
  // Code that runs when an unhandled error occurs

  // Get the exception object.
  Exception exc = Server.GetLastError();

  // Handle HTTP errors
  if (exc.GetType() == typeof(HttpException))
  {
    // The Complete Error Handling Example generates
    // some errors using URLs with "NoCatch" in them;
    // ignore these here to simulate what would happen
    // if a global.asax handler were not implemented.
    if (exc.Message.Contains("NoCatch") || exc.Message.Contains("maxUrlLength"))
    return;

   //Redirect HTTP errors to HttpError page
   Server.Transfer("HttpErrorPage.aspx");
 }

 // For other kinds of errors give the user some information
 // but stay on the default page
 Response.Write("<h2>Global Page Error</h2>\n");
 Response.Write(
     "<p>" + exc.Message + "</p>\n");
 Response.Write("Return to the <a href='Default.aspx'>" +
  "Default Page</a>\n");

  // Log the exception and notify system operators
  ExceptionUtility.LogException(exc, "DefaultPage");
  ExceptionUtility.NotifySystemOps(exc);

  // Clear the error from the server
  Server.ClearError();
}

person Fawn    schedule 21.07.2014    source источник
comment
msdn.microsoft.com/library/24395wz3.aspx   -  person Fawn    schedule 21.07.2014
comment
Я использую следующие ссылки для примеров кода того, что я пытаюсь реализовать. msdn.microsoft.com/en-us/library/bb397417.aspx   -  person Fawn    schedule 21.07.2014
comment
Изменить protection void Application_Error на protected void Application_Error   -  person Marek Musielak    schedule 24.07.2014


Ответы (1)


Я думаю, что вы должны добавить код в файл .cs.

Тем более защита не принимается. Ваш код должен быть таким:

void Application_Error(object sender, EventArgs e)
{            
  //DoSomething();
}
person mehran ghainian    schedule 14.04.2017