0

I have added the following code to my Application Startup, but the INFO is not showing up in my logs.

Sitecore 7.5

Is this code being called at all? If not, what am I doing wrong?

public class Global : Sitecore.ContentSearch.SolrProvider.NinjectIntegration.NinjectApplication
{
    protected void Application_Start(Object sender, EventArgs e)
    {
        System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
        Log.Info("Now Using Tls12 SecurityProtocol", this);
    }
}

EDIT:

When I removed the "protected" setting, the logging worked. But, my connection to Solr stopped working. When I added the "public" setting, the connection to Solr started working, but the logging stopped working. If I explicitly set it as "internal", nothing gets logged.

0

1 Answer 1

8

When working with the Global.asax file, even though the question is inheriting from Sitecore.ContentSearch.SolrProvider.NinjectIntegration.NinjectApplication, if you keep digging down, eventually you'll find that also inherits from the HttpApplication class. Ordinarily, this class exists in the System.Web namespace.

However, when choosing protected as your access modifier, what you are really saying is that the method is only available if subclassed. See this chart below for an visual on how the different access modifiers affect based on how the method is being accessed.

                | highest precedence <---------> lowest precedence
*———————————————+————————————————+———————————+———————————————+———————
 \ xCanBeSeenBy | this           | any class | this subclass | any
  \__________   | class          | in same   | in another    | class
             \  | nonsubbed      | library   | library       | any
Modifier of x \ |                |           |               | library   
————————————————*————————————————+———————————+———————————————+———————
public          |       ✔        |    ✔     |    ✔          |   ✔   
————————————————+————————————————+———————————+———————————————+———————
protected       |       ✔        |    ✔     |    ✔          |   ✘   
————————————————+————————————————+———————————+———————————————+———————
internal        |                |           |               |
(no modifier)   |       ✔        |    ✔     |    ✘          |   ✘   
————————————————+————————————————+———————————+—————————-—————+———————
private         |       ✔        |    ✘     |    ✘          |   ✘   

(chart citation)

When Application_Start is being called, it's actually being called from outside the subclass or class namespace, and thus must be visible to any class.

By protecting the method, you are essentially saying that it is only available to any class that inherits from your version of the Global class, or within the same package, or within the same class. This is why your method wasn't firing.

Resolution

Change protected to public as shown below:

public class Global : Sitecore.ContentSearch.SolrProvider.NinjectIntegration.NinjectApplication
{
    public void Application_Start(Object sender, EventArgs e)
    {
        System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
        Log.Info("Now Using Tls12 SecurityProtocol", this);
    }
}

Additional Fun Fact

In version 8.2 of Sitecore, the Global.asax has been set to inherit from Sitecore.Web.Application. Furthermore, Application_Start() has been made internal so that it can not be overridden.

2
  • Funnier Fact, I also need to make this change to 8.2.
    – ADH
    Mar 28, 2017 at 13:02
  • I would suggest using a <initialize> pipeline processor in order to accomplish this change.. Potentially in both versions of Sitecore.
    – Pete Navarra
    Mar 28, 2017 at 13:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.