G
Guest
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.GetCodeDirectoryAssembly(VirtualPath
virtualDir, CodeDirectoryType dirType, String assemblyName, StringSet
excludedSubdirectories, Boolean isDirectoryAllowed)
at System.Web.Compilation.BuildManager.CompileCodeDirectory(VirtualPath
virtualDir, CodeDirectoryType dirType, String assemblyName, StringSet
excludedSubdirectories)
at System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled()
[HttpException]: The path '/App_GlobalResources/' maps to a directory
outside this application, which is not supported.
at System.Web.Compilation.BuildManager.ReportTopLevelCompilationException()
at System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled()
at System.Web.Compilation.BuildManager.GetGlobalAsaxTypeInternal()
at System.Web.HttpApplicationFactory.CompileApplication()
at System.Web.HttpApplicationFactory.Init()
at System.Web.HttpApplicationFactory.EnsureInited()
at System.Web.HttpApplicationFactory.GetApplicationInstance(HttpContext
context)
at System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest 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!
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.GetCodeDirectoryAssembly(VirtualPath
virtualDir, CodeDirectoryType dirType, String assemblyName, StringSet
excludedSubdirectories, Boolean isDirectoryAllowed)
at System.Web.Compilation.BuildManager.CompileCodeDirectory(VirtualPath
virtualDir, CodeDirectoryType dirType, String assemblyName, StringSet
excludedSubdirectories)
at System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled()
[HttpException]: The path '/App_GlobalResources/' maps to a directory
outside this application, which is not supported.
at System.Web.Compilation.BuildManager.ReportTopLevelCompilationException()
at System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled()
at System.Web.Compilation.BuildManager.GetGlobalAsaxTypeInternal()
at System.Web.HttpApplicationFactory.CompileApplication()
at System.Web.HttpApplicationFactory.Init()
at System.Web.HttpApplicationFactory.EnsureInited()
at System.Web.HttpApplicationFactory.GetApplicationInstance(HttpContext
context)
at System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest 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!