Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions WebActivator/ActivationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Security;
using System.Web;
using System.Web.Compilation;
using System.Web.Configuration;
using System.Web.Hosting;

namespace WebActivatorEx
Expand All @@ -27,13 +28,32 @@ public static void Run()
{
if (!_hasInited)
{
// In CBM mode, pass true so that only the methods that have RunInDesigner=true get called
RunPreStartMethods(designerMode: HostingEnvironment.InClientBuildManager);
bool isRunningMono = Type.GetType("Mono.Runtime") != null;

if (isRunningMono)
{
RunPreStartMethods(designerMode: false);
}
else
{
// In CBM mode, pass true so that only the methods that have RunInDesigner=true get called
RunPreStartMethods(designerMode: IsInClientBuildManager());
}

// Register our module to handle any Post Start methods. But outside of ASP.NET, just run them now
if (HostingEnvironment.IsHosted)
{
Microsoft.Web.Infrastructure.DynamicModuleHelper.DynamicModuleUtility.RegisterModule(typeof(StartMethodCallingModule));
Type startMethodType = typeof(StartMethodCallingModule);

if (isRunningMono)
{
HttpModuleActionCollection modules = (WebConfigurationManager.GetWebApplicationSection("system.web/httpModules") as HttpModulesSection).Modules;
modules.Add(new HttpModuleAction(startMethodType.FullName, startMethodType.AssemblyQualifiedName));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know you could do this. Does this work in .NET as well, or only Mono?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not check because I assumed it'd be safer to stick with what was there.

I peeked inside and it seems that DynamicModuleUtility.RegisterModule() then simply invokes System.Web.HttpApplication.RegisterModule(), another method not implemented in Mono.

I'm not sure what the base implementation in HttpApplication is but whatever it is, it currently works in .NET. Best to stick with that.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I was just curious. BTW, the reason I'm calling DynamicModuleUtility.RegisterModule() instead of HttpApplication.RegisterModule() is that the former existed in earlier versions of the framework (4.0 vs 4.5 I think), so it gives great compat.

}
else
{
Microsoft.Web.Infrastructure.DynamicModuleHelper.DynamicModuleUtility.RegisterModule(startMethodType);
}
}
else
{
Expand All @@ -44,6 +64,11 @@ public static void Run()
}
}

private static bool IsInClientBuildManager()
{
return HostingEnvironment.InClientBuildManager;
}

private static IEnumerable<Assembly> Assemblies
{
get
Expand Down
3 changes: 2 additions & 1 deletion WebActivator/WebActivator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<HintPath>..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Web" />
<Reference Include="System.Xml.Linq" />
Expand Down Expand Up @@ -70,4 +71,4 @@
<SignAssembly>true</SignAssembly>
<DelaySign>false</DelaySign>
</PropertyGroup>
</Project>
</Project>