Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 852769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:39:13+00:00 2026-05-15T07:39:13+00:00

I have successfully created an iHttpModule to replace my Global.asax file in many Web

  • 0

I have successfully created an iHttpModule to replace my Global.asax file in many Web Forms applications. But in looking at the Global.asax file in my MVC application, the methods are totally different.

I’m wondering if it is still possible to create this same thing in an MVC app. I know it’s not necessary and the Global.asax works just fine. I suppose I just want to have nothing but the web.config in the root directory of my application.

Also, I am putting all of my classes in a separate class library project instead of a folder in my MVC application. Not sure if this makes a difference or not.

Here’s what I have currently, but unfortunately my routes are not registering

MVCApplication.vb (Class)

Imports System.Web.Mvc
Imports System.Web.Routing
Imports System.Web
Imports System.Text.RegularExpressions

Public Class MvcApplication : Inherits System.Web.HttpApplication : Implements IHttpModule

#Region "Global Variables/Objects"

    Private UrlRegex As New Regex("(http|https)://www\.", RegexOptions.IgnoreCase Or RegexOptions.Compiled)
    Private ApplicationContext As HttpApplication
    Private BeginRequestEventHandler As EventHandler
    Private ErrorEventHandler As EventHandler
#End Region

#Region "Init and Dispose"

    Public Overrides Sub Dispose() Implements System.Web.IHttpModule.Dispose
        RemoveHandler ApplicationContext.BeginRequest, BeginRequestEventHandler : BeginRequestEventHandler = Nothing
        RemoveHandler ApplicationContext.Error, ErrorEventHandler : ErrorEventHandler = Nothing
    End Sub

    Public Overridable Overloads Sub Init(ByVal context As System.Web.HttpApplication) Implements System.Web.IHttpModule.Init
        ApplicationContext = context
        AddHandler ApplicationContext.BeginRequest, AddressOf OnBeginRequest
        AddHandler ApplicationContext.Error, AddressOf OnError
    End Sub
#End Region

    Protected Sub OnBeginRequest(ByVal sender As Object, ByVal e As EventArgs)
       ''# Crap in here about redirecting WWW
    End Sub

    Protected Sub OnError(ByVal sender As Object, ByVal e As EventArgs)
        ''# crap in here about logging errors
    End Sub




    Shared Sub RegisterRoutes(ByVal routes As RouteCollection)
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}")

        ''# MapRoute takes the following parameters, in order:
        ''# (1) Route name
        ''# (2) URL with parameters
        ''# (3) Parameter defaults
        routes.MapRoute( _
            "Default", _
            "{controller}/{action}/{id}", _
            New With { _
                .controller = "Home", _
                .action = "Index", _
                .id = UrlParameter.Optional} _
        )

    End Sub


    Sub Application_Start()
        AreaRegistration.RegisterAllAreas()
        RegisterRoutes(RouteTable.Routes)
    End Sub
End Class

web.Config

  <system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
      <modules runAllManagedModulesForAllRequests="true">
          <add name="_Global" type="UrbanNow.hClassLib.MvcApplication"/>
      </modules>
  </system.webServer>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T07:39:14+00:00Added an answer on May 15, 2026 at 7:39 am

    What aspects of MVC do you want to push into your IHttpModule? The problem with this scenario is that an IHttpModule is executed on each request, whereas the Global.asax method is used (mostly) for performing first-run application configuration. What exactly are you trying to achieve?

    You can subclass the HttpApplication class instead, and inherit from that in code, so in your supporting library, do something like this:

    public class MyCustomApplication : HttpApplication
    {
        public void Application_Start() {
    
        }
    }
    

    And change your Global.asax.cs class to inherit from MyCustomApplication instead of HttpApplication.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have successfully created a simple RSS feed, but entries keep coming back as
I have successfully created a asp mvc app which basically has interface, service and
I have successfully created an app that reads from a bundled .plist file and
I have successfully created an email that sends on creation of a Kase, but
I have been using Hibernate very successfully, but today I noticed a bizarre phenomenon
I have successfully created (and manually edited) an Item Template that will add a
I have successfully created rewrite rules to handle URLs like http://example.com/xyz http://example.com/xyz/ http://example.com/xyz/abc http://example.com/xyz/abc/
I have successfully created a WCF RIA service by creating DomainService class and accessing
I have successfully created a WS client that works correctly when NOT using authentication.
I have successfully created my data source, which is a CLR object of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.