Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
26 changes: 23 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: (bool)typeof(HostingEnvironment).GetProperty("InClientBuildManager").GetValue(null, null) == true);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Strange, I had a comment here but it's gone. You can avoid reflection here by moving this to a helper method and calling the real thing (assuming Mono jitter works the same as .NET).

}

// 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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 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>