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:
| Step | Effect |
|---|---|
| Register Areas | Loads all *AreaRegistration.cs classes; enables {area}/... URLs |
| Global filters | Registers MVC filters (validation, etc.) |
| Routes | Maps default {controller}/{action}/{id} → Login/Index |
| Bundles | Registers CSS/JS bundles for optimization |
| Disable MVC header | Removes X-AspNetMvc-Version response header |
Per-request lifecycle
Application_BeginRequest — HTTPS
When appSettings["ForceHttps"] equals "true" (case-insensitive):
- Skip redirect for local requests (
Request.IsLocal) - Skip if connection is already secure
- Otherwise issue
RedirectPermanenttohttps://{host}{pathAndQuery}
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:
- Read
Server.GetLastError() - Build
RouteDatatargetingManageErrorController - Set action to
E404for HTTP 404; otherwiseIndex - Pass
url,userAddress, anderrorinto route values Server.ClearError()andResponse.TrySkipIisCustomErrors = true- Manually execute
ManageErrorController - 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:
ServerX-AspNet-VersionX-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:
| Setting | Value |
|---|---|
| Default URL | {controller}/{action}/{id} |
| Defaults | controller = Login, action = Index, id = optional |
| Ignored routes | {resource}.axd/{*pathInfo} |
| Crystal handler | Ignores 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
CrystalImageHandlerprevents 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
| URL | Resolved target |
|---|---|
/ | LoginController.Index |
/Dashboard/Index | DashboardController.Index |
/Payroll/PayrollDashboard/Index | Area Payroll → PayrollDashboardController.Index |
/Adminisration/UserDashBoard/Index | Area Adminisration → UserDashBoardController.Index |
404 flow
Request unknown URL
→ HttpException 404
→ Application_Error sets action E404
→ ManageErrorController.E404()
→ Views/ManageError/E404.cshtml
Related Pages
Important Notes
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.
Response.TrySkipIisCustomErrors = true ensures your MVC error view wins over IIS generic error pages. Verify this when deploying to new servers.
Common Mistakes
| Mistake | Consequence |
|---|---|
Setting ForceHttps=true without SSL binding | Redirect loop or connection failures |
| Adding a root route that shadows an Area name | Wrong controller invoked |
| Removing Crystal ignore route | Report images fail to load |
Expecting [Authorize] on all controllers | Many actions only check Session["CompID"] manually |
Next Steps
- Read Error Handling for Area-level error controllers and AJAX redirect patterns.
- Read Authentication Flow to see how login fits into the default route.