ApplicationHost and HttpModule problem

  • Thread starter Thread starter Vlad Losev
  • Start date Start date
V

Vlad Losev

I am trying to execute a web page in application host (without IIS) using
ApplicationHost, but have a ConfigurationException thrown. I have several
HttpModule add directives in Web.config but cannot remove them, it would
cripple my application). I wonder if there is any way to get rid of this
error?

[ConfigurationException]: The module 'CommerceApplication' is already in the
application and cannot be added again (C:\Inetpub\wwwroot\dotnet\web.config
line 80)
at System.Web.Configuration.HttpConfigurationRecord.Evaluate(String
configKey, SectionRecord section)
at System.Web.Configuration.HttpConfigurationRecord.GetConfig(String
configKey, Boolean cacheResult)
at System.Web.Configuration.HttpConfigurationRecord.get_Item(String
configKey)
at System.Web.HttpContext.GetAppConfig(String name)
at System.Web.HttpApplication.InitModules()
at System.Web.HttpApplication.InitInternal(HttpContext context,
HttpApplicationState state, MethodInfo[] handlers)
at
System.Web.HttpApplicationFactory.GetNormalApplicationInstance(HttpContext
context)
at System.Web.HttpApplicationFactory.GetApplicationInstance(HttpContext
context)
at System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr)

Here is a section of my web.config that describes the http modules:
<system.web>
<httpModules>
<add name="CommerceApplication"
type="Microsoft.CommerceServer.Runtime.CommerceApplicationModule,
Microsoft.CommerceServer.Runtime, Version=4.5.2002.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35"/>
<add name="CommerceAuthentication"
type="Microsoft.CommerceServer.Runtime.CommerceAuthenticationModule,
Microsoft.CommerceServer.Runtime, Version=4.5.2002.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35"/>
<add name="CommerceProfile"
type="Microsoft.CommerceServer.Runtime.Profiles.CommerceProfileModule,
Microsoft.CommerceServer.Runtime, Version=4.5.2002.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35"/>
<add name="CommerceExpressionEvaluator"
type="Microsoft.CommerceServer.Runtime.Targeting.CommerceExpressionModule,
Microsoft.CommerceServer.Runtime, Version=4.5.2002.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35"/>
<add name="CommerceCache"
type="Microsoft.CommerceServer.Runtime.Caching.CommerceCacheModule,
Microsoft.CommerceServer.Runtime, Version=4.5.2002.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35"/>
</httpModules>
<!-- The rest of system.web -->
</System.web>

I have used the code published at
http://radio.weblogs.com/0105476/stories/2002/07/12/executingAspxPagesWithoutAWebServer.html:
using System;
using System.Web;
using System.Web.Hosting;
using System.IO;
using System.Runtime.Remoting;
using System.Globalization;
namespace AspHostTest
{
public class MyExeHost : MarshalByRefObject
{
public void ProcessRequest(String page)
{
HttpWorkerRequest hwr =
new SimpleWorkerRequest(page, null, Console.Out);
HttpRuntime.ProcessRequest(hwr);
}
}
class MyAspHost
{
public static object CreateApplicationHost(Type hostType, string
virtualDir, string physicalDir)
{
if (!(physicalDir.EndsWith("\\")))
physicalDir = physicalDir + "\\";
string aspDir = HttpRuntime.AspInstallDirectory;
string domainId =
DateTime.Now.ToString(DateTimeFormatInfo.InvariantInfo).GetHashCode().ToStri
ng("x");
string appName = (virtualDir +
physicalDir).GetHashCode().ToString("x");
AppDomainSetup setup = new AppDomainSetup();
setup.ApplicationName = appName;
setup.ConfigurationFile = "web.config"; // not necessary
execept for debugging
AppDomain ad = AppDomain.CreateDomain(domainId, null, setup);
ad.SetData(".appDomain", "*");
ad.SetData(".appPath", physicalDir);
ad.SetData(".appVPath", virtualDir);
ad.SetData(".domainId", domainId);
ad.SetData(".hostingVirtualPath", virtualDir);
ad.SetData(".hostingInstallDir", aspDir);
ObjectHandle oh =
ad.CreateInstance(hostType.Module.Assembly.FullName, hostType.FullName);
return oh.Unwrap();
}

static void Main(string[] args)
{
MyExeHost myHost =
(MyExeHost)CreateApplicationHost(typeof(MyExeHost),"/",Directory.GetCurrentD
irectory());
myHost.ProcessRequest("app.aspx");
}
}
}

Many thanks,
Vlad Losev
 
Vlad,

I'm afraid I don't know the solution to your problem, but I can tell you
that I've seen the same thing while working with the Cassini web server from
http://asp.net/. In my case, I was able to remove the offending items from
web.config for testing purposes, so I haven't come up with a solution, or
even a diagnosis. Sorry.

John Saunders
(e-mail address removed)


Vlad Losev said:
I am trying to execute a web page in application host (without IIS) using
ApplicationHost, but have a ConfigurationException thrown. I have several
HttpModule add directives in Web.config but cannot remove them, it would
cripple my application). I wonder if there is any way to get rid of this
error?

[ConfigurationException]: The module 'CommerceApplication' is already in the
application and cannot be added again (C:\Inetpub\wwwroot\dotnet\web.config
line 80)
at System.Web.Configuration.HttpConfigurationRecord.Evaluate(String
configKey, SectionRecord section)
at System.Web.Configuration.HttpConfigurationRecord.GetConfig(String
configKey, Boolean cacheResult)
at System.Web.Configuration.HttpConfigurationRecord.get_Item(String
configKey)
at System.Web.HttpContext.GetAppConfig(String name)
at System.Web.HttpApplication.InitModules()
at System.Web.HttpApplication.InitInternal(HttpContext context,
HttpApplicationState state, MethodInfo[] handlers)
at
System.Web.HttpApplicationFactory.GetNormalApplicationInstance(HttpContext
context)
at System.Web.HttpApplicationFactory.GetApplicationInstance(HttpContext
context)
at System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr)

Here is a section of my web.config that describes the http modules:
<system.web>
<httpModules>
<add name="CommerceApplication"
type="Microsoft.CommerceServer.Runtime.CommerceApplicationModule,
Microsoft.CommerceServer.Runtime, Version=4.5.2002.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35"/>
<add name="CommerceAuthentication"
type="Microsoft.CommerceServer.Runtime.CommerceAuthenticationModule,
Microsoft.CommerceServer.Runtime, Version=4.5.2002.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35"/>
<add name="CommerceProfile"
type="Microsoft.CommerceServer.Runtime.Profiles.CommerceProfileModule,
Microsoft.CommerceServer.Runtime, Version=4.5.2002.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35"/>
<add name="CommerceExpressionEvaluator"
type="Microsoft.CommerceServer.Runtime.Targeting.CommerceExpressionModule,
Microsoft.CommerceServer.Runtime, Version=4.5.2002.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35"/>
<add name="CommerceCache"
type="Microsoft.CommerceServer.Runtime.Caching.CommerceCacheModule,
Microsoft.CommerceServer.Runtime, Version=4.5.2002.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35"/>
</httpModules>
<!-- The rest of system.web -->
</System.web>

I have used the code published at
http://radio.weblogs.com/0105476/stories/2002/07/12/executingAspxPagesWithoutAWebServer.html:
using System;
using System.Web;
using System.Web.Hosting;
using System.IO;
using System.Runtime.Remoting;
using System.Globalization;
namespace AspHostTest
{
public class MyExeHost : MarshalByRefObject
{
public void ProcessRequest(String page)
{
HttpWorkerRequest hwr =
new SimpleWorkerRequest(page, null, Console.Out);
HttpRuntime.ProcessRequest(hwr);
}
}
class MyAspHost
{
public static object CreateApplicationHost(Type hostType, string
virtualDir, string physicalDir)
{
if (!(physicalDir.EndsWith("\\")))
physicalDir = physicalDir + "\\";
string aspDir = HttpRuntime.AspInstallDirectory;
string domainId =
DateTime.Now.ToString(DateTimeFormatInfo.InvariantInfo).GetHashCode().ToStri
ng("x");
string appName = (virtualDir +
physicalDir).GetHashCode().ToString("x");
AppDomainSetup setup = new AppDomainSetup();
setup.ApplicationName = appName;
setup.ConfigurationFile = "web.config"; // not necessary
execept for debugging
AppDomain ad = AppDomain.CreateDomain(domainId, null, setup);
ad.SetData(".appDomain", "*");
ad.SetData(".appPath", physicalDir);
ad.SetData(".appVPath", virtualDir);
ad.SetData(".domainId", domainId);
ad.SetData(".hostingVirtualPath", virtualDir);
ad.SetData(".hostingInstallDir", aspDir);
ObjectHandle oh =
ad.CreateInstance(hostType.Module.Assembly.FullName, hostType.FullName);
return oh.Unwrap();
}

static void Main(string[] args)
{
MyExeHost myHost =
(MyExeHost)CreateApplicationHost(typeof(MyExeHost),"/",Directory.GetCurrentD
irectory());
myHost.ProcessRequest("app.aspx");
}
}
}

Many thanks,
Vlad Losev
 
Back
Top