Hosting ASP.Net fails after upgrade to .Net 2

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



I have been hosting ASP.Net in my app for some time, with no problems, with
framework 1.1 (VS 2003). Having just upgraded to 2.0 (VS 2005), and it now
gives this error:

HttpException (0x80004005): The path '/MyApp/App_GlobalResources/' maps to a
directory outside this application, which is not supported.

The ApplicationBase for my app is "/MyApp" so the statement in the error
message would appear to be incorrect. I have no explicit mapping for
"App_GlobalResources". It makes no difference whether the subfolder actually
exists.

Here's the code that creates the host:

public static Host Create(Type HostType, string VirtualDir, string
PhysicalDir, string AppBase, string BinPath)
{
if (!PhysicalDir.EndsWith("\\"))
PhysicalDir += "\\";

string aspDir = HttpRuntime.AspInstallDirectory;
string domainId = "ASPHOST_" +
DateTime.Now.ToString().GetHashCode().ToString("x");
string appName = (VirtualDir + PhysicalDir).GetHashCode().ToString("x");
AppDomainSetup setup = new AppDomainSetup();
setup.ApplicationName = appName;
setup.ConfigurationFile = "web.config";
setup.ApplicationBase = AppBase!=null ? AppBase : (AppBase = PhysicalDir);
setup.PrivateBinPath = BinPath!=null ? BinPath : AppBase + "bin";
setup.PrivateBinPathProbe = "*"; // if non-blank, excludes AppBase from
search path, so only looks in PrivateBinPath.
setup.DisallowCodeDownload = true;

AppDomain ad = AppDomain.CreateDomain(domainId, null, setup);
ad.SetData(".appDomain", "*");
ad.SetData(".appPath", PhysicalDir);
ad.SetData(".appVPath", VirtualDir);
ad.SetData(".domainId", domainId);

// VS2003 only:
//ad.SetData(".hostingVirtualPath", VirtualDir);
//ad.SetData(".hostingInstallDir", aspDir);

// VS2005 only:
ad.SetData(".appId", appName);
string dataDir = PhysicalDir + "App_Data";
ad.SetData("DataDirectory", dataDir, new
System.Security.Permissions.FileIOPermission(System.Security.Permissions.FileIOPermissionAccess.PathDiscovery,
dataDir));

Host host =
(Host)ad.CreateInstanceAndUnwrap(HostType.Module.Assembly.FullName,
HostType.FullName);
return host;
}

The other way to create a host is to use the ApplicationHost CLR class, as
in the following code, whic does work. It is simpler, but does not allow
control of PrivateBinPath. By the time CreateApplicationHost returns,
assemblies have been loaded in the new AppDomain, so it is too late to set
it. That's why I need to use the above method.

public static Host Create(Type HostType, string VirtualDir, string
PhysicalDir)
{
Host newHost = (Host)ApplicationHost.CreateApplicationHost(HostType,
VirtualDir, PhysicalDir);
return newHost;
}

The line 'ad.SetData("DataDirectory" ...etc.' in the first method makes no
difference, I included it in an attempt to mimic the AppDomain created by
the second method (I saw in the debugger that it added such an entry).
Granting 'AllAccess' instead of 'PathDiscovery' makes no difference either.

Thanks
Paul Newman




.



Relevant Pages

  • Re: Struggling to convert a mysql datetime object to a python string of a different format
    ... I google a lot but couldnt found out how to format it being a string ... cursor.execute(''' SELECT host, hits, date FROM visitors WHERE page ... Could 'dataset' be a 'list of lists' as well? ...
    (comp.lang.python)
  • Re: Hosting ASP.Net fails after upgrade to .Net 2
    ... The ApplicationBase for my app is "/MyApp" so the statement in the error ... Here's the code that creates the host: ... public static Host Create(Type HostType, string VirtualDir, string ... assemblies have been loaded in the new AppDomain, so it is too late to set ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Typosquatting
    ... interpreted string is either a quoted-string or a dot-atom. ... In the dot-atom form, this is interpreted as an Internet ... particular host. ...
    (sci.electronics.design)
  • Re: String substitution VS proper mysql escaping
    ... |>correctly escape a string for insertion into an SQL statement. ...
    (comp.lang.python)
  • Re: Winsock CGI
    ... .RemoteHost = Host ... End With ... Private Sub Winsock1_Connect ... Private Function encode(s as string) as string ...
    (microsoft.public.de.vb)