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

Re: ApplicationHost and HttpModule problem by John

John
Sun Jul 06 10:14:43 CDT 2003

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
john.saunders@surfcontrol.com


"Vlad Losev" <vlosev@fairisaac.no.spam.at.all.com> wrote in message
news:%23R$Z3HSQDHA.1072@TK2MSFTNGP10.phx.gbl...
> 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
>
>