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 8260301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:04:11+00:00 2026-06-08T03:04:11+00:00

I have a situation where I am building a web service hosted on IIS

  • 0

I have a situation where I am building a web service hosted on IIS that requires a license file to be on the filesystem before starting up successfully. I’m wondering where I should put the code that does the license check to prevent the Website from actually starting.

I have found there is a function Application_Start but this isn’t called until someone makes an initial request.

Ideally, the app would check the license and log an error in the Windows Event Log when the IIS Admin tries to start the website itself. Is this possible? If not, are there any best practices for this type of situation?

  • 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-06-08T03:04:12+00:00Added an answer on June 8, 2026 at 3:04 am

    Bombing an entire website because a part of it that uses your component which isn’t registered is very bad form.

    To that end, I you could put something in the static constructor(s) of your class(es) that checks the licensing and then throws an exception (any will do) if your licensing requirements are not found, like so:

    public static MyComponent
    {
        static MyComponent()
        {
             // Check for licensing here.
             if (!<licensing condition>)
             {
                 // Bomb the app.
                 throw new InvalidOperationException("Component is not licensed.");
             }
        }
    }
    

    If you really want to bomb the entire website, then you’ll more than likely have to do this outside of ASP.NET, and write an ISAPI filter (note, you have to do it in unmanaged code) and get it installed on the IIS server.

    Or, you could implement the IHttpModule interface. In the Init method implementation you could check for your licensing requirements. If the requirements are not set, then throw an exception, like so:

    public class MyLicensingHttpModule : IHttpModule
    {
        public void Init(HttpApplication context)
        {
             // Check for licensing here.
             if (!<licensing condition>)
             {
                 // Bomb the app.
                 throw new InvalidOperationException("Component is not licensed.");
             }            
        }
    }
    

    (Note that you still have to register the IHttpModule implementation)

    A better solution would be to implement IHttpModule, but set a flag that your libraries/components can access as needed:

    public class MyLicensingHttpModule : IHttpModule
    {
        // Set when the application is initialized
        public static IsLicensed { get; private set; }
    
        public void Init(HttpApplication context)
        {
             // Check for licensing here.  Set
             // the flag accordingly.
             IsLicensded = <licensing condition>;
        }
    }
    

    The flag would subsequently be checked for in every constructor and/or static constructor to ensure compliance:

    public class MyComponentA
    {
         static MyComponentA()
         {
              // Check here.
              if (!MyLicensingHttpModule.IsLicensed)
              {
                  // Bomb the *type*.
                  throw new InvalidOperationException(
                      "MyComponentA is not licensed.");
              }
         }
    }
    
    public class MyComponentB
    {
         public MyComponentB()
         {
              // Or check on a per-instance basis.  You'd do
              // this if you needed properties on the class level
              // to be available regardless.  This is the
              // *less* likely scenario.
              if (!MyLicensingHttpModule.IsLicensed)
              {
                  // Bomb the *instance*.
                  throw new InvalidOperationException(
                      "MyComponentA is not licensed.");
              }
         }
    }
    

    This would force installation of the module (without it, the flag is not set, which would cause an exception to the thrown), and should give you the opportunity to hook into every page request that uses your component and prevent usage if you wish.

    If you do go this route, I have to reemphasize that it’s in very bad form to bomb the entire application, and you should really focus on your component when it is used; this isn’t really your call to make.

    It’s very possible that the developer(s) have other pages that do not use your component, while using other paid components which should render just fine.

    Also, if you hook into every request, you should make sure that you don’t do anything to incur a performance hit. That would also be in bad form as well. This is why you set the flag once and then do a simple check when you need to.

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

Sidebar

Related Questions

I'm having the following situation: I'm building an application that requires a service. The
I have a unique situation where I'm building a site that will call data
I am building an ASP.NET web service that will be used internally in my
I'm building a web application (using prototype) that requires the addition of large chunks
Situation: I have a calculator that I am building with js. It is a
I am building a Winform web browser. I have a history.xml file which stores
I have situation, where running a query that filters by an indexed column in
We have situation where say we have four engineers that are working on software
I am building an iPad app that requires only the middle section of a
The situation I have is that I'm querying MongoDB with a string for a

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.