Skip to main content

Request Pipeline

Introduction

Every HTTP request to Damsy ERP passes through the ASP.NET pipeline configured in Global.asax, RouteConfig, and per-Area registration classes. Understanding this pipeline helps you debug redirects, HTTPS behavior, unhandled exceptions, and route resolution.

Purpose

This page documents what happens before and after your controller action runs: application startup, optional HTTPS forcing, header stripping, routing, and centralized error dispatch.

When to Use

Refer to this page when you:

  • Configure HTTPS for production IIS
  • Debug why a URL resolves to the wrong controller
  • Trace an unhandled exception to the error page
  • Add a new Area or change default routes
  • Investigate Crystal Reports image handler routing

How It Works

Application startup

MvcApplication.Application_Start() in Global.asax.cs runs once when the app pool starts:

StepEffect
Register AreasLoads all *AreaRegistration.cs classes; enables {area}/... URLs
Global filtersRegisters MVC filters (validation, etc.)
RoutesMaps default {controller}/{action}/{id}Login/Index
BundlesRegisters CSS/JS bundles for optimization
Disable MVC headerRemoves X-AspNetMvc-Version response header

Per-request lifecycle

Application_BeginRequest — HTTPS

When appSettings["ForceHttps"] equals "true" (case-insensitive):

  1. Skip redirect for local requests (Request.IsLocal)
  2. Skip if connection is already secure
  3. Otherwise issue RedirectPermanent to https://{host}{pathAndQuery}
Local development

IIS Express over HTTP continues to work when ForceHttps is absent or not true. Enable HTTPS forcing only in production configs.

Application_Error — global exception handler

Unhandled exceptions trigger Application_Error:

  1. Read Server.GetLastError()
  2. Build RouteData targeting ManageErrorController
  3. Set action to E404 for HTTP 404; otherwise Index
  4. Pass url, userAddress, and error into route values
  5. Server.ClearError() and Response.TrySkipIisCustomErrors = true
  6. Manually execute ManageErrorController
  7. Log via ErrorHandling.LogFileWrite(exception)

This bypasses the normal MVC pipeline so users always see a controlled error page instead of a yellow screen of death.

Application_PreSendRequestHeaders

Removes fingerprinting headers when the host allows it:

  • Server
  • X-AspNet-Version
  • X-AspNetMvc-Version

Failures are swallowed — some hosting environments block header removal.

Session_End

When a session expires, Session_End logs the session ID and CompID (used as a user identifier in the log message) via ErrorHandling.LogFileWrite.

RouteConfig

Default route registration in App_Start/RouteConfig.cs:

SettingValue
Default URL{controller}/{action}/{id}
Defaultscontroller = Login, action = Index, id = optional
Ignored routes{resource}.axd/{*pathInfo}
Crystal handlerIgnores paths matching CrystalImageHandler

Effective landing URL: / and /Login/Index both resolve to the login page.

Area routes are registered separately by each AreaRegistration class with the pattern:

{area}/{controller}/{action}/{id}

customErrors (Web.config)

<customErrors mode="RemoteOnly" defaultRedirect="~/ManageError/Index" />
  • RemoteOnly: Detailed errors locally; friendly redirect for remote clients
  • defaultRedirect: Fallback when ASP.NET handles an error outside Application_Error

Combined with Application_Error, this gives two layers of error presentation.

Developer Notes

  • Crystal Reports routing: The ignore route for CrystalImageHandler prevents MVC from intercepting Crystal's dynamic image requests.
  • Area route precedence: Area routes are typically more specific; ensure new root routes do not conflict with Area names.
  • ManageError is AllowAnonymous: Error pages render even when session has expired.
  • No OWIN middleware pipeline for most requests — authentication is session-based in controllers, not ASP.NET Identity middleware for module pages.

Examples

Enable HTTPS in production Web.config

<appSettings>
<add key="ForceHttps" value="true" />
</appSettings>

URL resolution examples

URLResolved target
/LoginController.Index
/Dashboard/IndexDashboardController.Index
/Payroll/PayrollDashboard/IndexArea Payroll → PayrollDashboardController.Index
/Adminisration/UserDashBoard/IndexArea Adminisration → UserDashBoardController.Index

404 flow

Request unknown URL
→ HttpException 404
→ Application_Error sets action E404
→ ManageErrorController.E404()
→ Views/ManageError/E404.cshtml

Important Notes

Application_Error replaces the pipeline

After Application_Error, the original controller action does not run. Do not rely on finally blocks in controllers for critical cleanup of unhandled exceptions — use explicit try/catch where needed.

IIS custom errors

Response.TrySkipIisCustomErrors = true ensures your MVC error view wins over IIS generic error pages. Verify this when deploying to new servers.

Common Mistakes

MistakeConsequence
Setting ForceHttps=true without SSL bindingRedirect loop or connection failures
Adding a root route that shadows an Area nameWrong controller invoked
Removing Crystal ignore routeReport images fail to load
Expecting [Authorize] on all controllersMany actions only check Session["CompID"] manually

Next Steps

  1. Read Error Handling for Area-level error controllers and AJAX redirect patterns.
  2. Read Authentication Flow to see how login fits into the default route.