Hi all,
For some reasons I need host ASP.NET, in the network I found such code:
using System;
using System.IO;
using System.Web;
using System.Web.Hosting;
using System.Reflection;
using System.Diagnostics;
using System.Globalization;
public class Asmx2WsdlHost : MarshalByRefObject
{
public void ProcessRequest(String page)
{
HttpWorkerRequest hwr = new SimpleWorkerRequest(
page,
"WSDL",
Console.Out);
HttpRuntime.ProcessRequest(hwr);
}
}
public class App
{
public static Asmx2WsdlHost CreateApplicationHost(
string virtualDir,
string physicalDir)
{
string appName = "ASPHOST";
string appId = (virtualDir + physicalDir).GetHashCode().ToString("x");
string aspDir = HttpRuntime.AspInstallDirectory;
string domainId = "ASPHOST_" +
DateTime.Now.ToString().GetHashCode().ToString("x" );
AppDomainSetup setup = new AppDomainSetup();
setup.ApplicationName = appName;
setup.ConfigurationFile = "web.config";
setup.ApplicationBase = physicalDir;
AppDomain loDomain = AppDomain.CreateDomain(domainId, null, setup);
loDomain.SetData(".appDomain", "*");
loDomain.SetData(".appId", appId);
loDomain.SetData(".appPath", physicalDir);
loDomain.SetData(".appVPath", virtualDir);
loDomain.SetData(".domainId", domainId);
loDomain.SetData(".hostingVirtualPath", virtualDir);
loDomain.SetData(".hostingInstallDir", aspDir);
return (Asmx2WsdlHost)loDomain.CreateInstance(
typeof(Asmx2WsdlHost).Assembly.FullName,
typeof(Asmx2WsdlHost).FullName).Unwrap();
}
public static int Main(string[] args)
{
try
{
Asmx2WsdlHost host = CreateApplicationHost(
@"/ASPHOST",
@"D:\PROJECTS\BIN");
host.ProcessRequest(@"CatiBridge.asmx");
}
catch (Exception e)
{
Trace.TraceError(e.ToString());
return 1;
}
return 0;
}
}
But, it throws exception:[HttpException]: The path '/App_GlobalResources/'
maps to a directory outside this application, which is not supported.
at
System.Web.Compilation.CodeDirectoryCompiler.GetCo deDirectoryAssembly(VirtualPath
virtualDir, CodeDirectoryType dirType, String assemblyName, StringSet
excludedSubdirectories, Boolean isDirectoryAllowed)
at System.Web.Compilation.BuildManager.CompileCodeDir ectory(VirtualPath
virtualDir, CodeDirectoryType dirType, String assemblyName, StringSet
excludedSubdirectories)
at System.Web.Compilation.BuildManager.EnsureTopLevel FilesCompiled()
[HttpException]: The path '/App_GlobalResources/' maps to a directory
outside this application, which is not supported.
at System.Web.Compilation.BuildManager.ReportTopLevel CompilationException()
at System.Web.Compilation.BuildManager.EnsureTopLevel FilesCompiled()
at System.Web.Compilation.BuildManager.GetGlobalAsaxT ypeInternal()
at System.Web.HttpApplicationFactory.CompileApplicati on()
at System.Web.HttpApplicationFactory.Init()
at System.Web.HttpApplicationFactory.EnsureInited()
at System.Web.HttpApplicationFactory.GetApplicationIn stance(HttpContext
context)
at System.Web.HttpRuntime.ProcessRequestInternal(Http WorkerRequest wr)
I have no idea why and how to fix it :( Please help if somebody know:
PS:
.NET Version v2.0.50727
Thanks a lot!