Access to Application object from exe

W

Woland

Hi,

I have many virtual directory with my web app. I'd like to create one exe
appliaction to administrating these web apps. Is it possible to access
Application object of web appliaction from exe appliaction?

With regards,

Woland
 
N

Natty Gur

As far as I know you cant. If you want i got an example that let you
access all AppDomaines (Applications) from ASP.NET page.

Natty Gur, CTO
Dao2Com Ltd.
28th Baruch Hirsch st. Bnei-Brak
Israel , 51114

Phone Numbers:
Office: +972-(0)3-5786668
Fax: +972-(0)3-5703475
Mobile: +972-(0)58-888377

Know the overall picture
 
W

Woland

Natty Gur said:
As far as I know you cant. If you want i got an example that let you
access all AppDomaines (Applications) from ASP.NET page.

Natty Gur, CTO

I'd be very grateful if you send me this app or link to the page where I can
look at it.

Thanks in advance,

Woland
Woland1(at)poczta.onet.pl
 
N

Natty Gur

1)You need to reference mscoree tlb.
2)the code :

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Reflection;
using System.Runtime.InteropServices;

namespace WebApplication3
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button btnStop;
protected System.Web.UI.WebControls.CheckBoxList CheckBoxList1;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if (!this.IsPostBack)

GetAllDomains();
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.CheckBoxList1.SelectedIndexChanged += new
System.EventHandler(this.CheckBoxList1_SelectedIndexChanged);
this.btnStop.Click += new System.EventHandler(this.btnStop_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void btnStop_Click(object sender, System.EventArgs e)
{
System.AppDomain.Unload (System.AppDomain.CurrentDomain );

mscoree.CorRuntimeHostClass host = new mscoree.CorRuntimeHostClass();
IntPtr enumHandle = IntPtr.Zero;
host.EnumDomains( out enumHandle );
object dom = null;
while(true)
{
host.NextDomain( enumHandle, out dom );
if( dom == null )
break;
AppDomain ad = (AppDomain) dom;
//dom = null;
for(int iIndx =0;iIndx < CheckBoxList1.Items.Count;iIndx++)
{
if ( CheckBoxList1.Items[iIndx].Value == ad.FriendlyName )
{
if ( CheckBoxList1.Items[iIndx].Selected == true )
{
System.Security.Policy.Evidence NE = new
System.Security.Policy.Evidence(ad.Evidence);
System.AppDomainSetup NADS = new System.AppDomainSetup();
NADS.ApplicationBase = ad.SetupInformation.ApplicationBase;
NADS.ApplicationName = ad.SetupInformation.ApplicationName;
NADS.ConfigurationFile = ad.SetupInformation.ConfigurationFile;
NADS.DynamicBase = ad.SetupInformation.DynamicBase;
NADS.PrivateBinPath = ad.SetupInformation.PrivateBinPath;
ad.ClearPrivatePath();
ad.ClearShadowCopyPath();
host.UnloadDomain( ad);
//host.DeleteLogicalThreadState ();
System.AppDomain.Unload (System.AppDomain.CurrentDomain );

//System.AppDomain.Unload(ad);
System.Web.Hosting.ApplicationHost.CreateApplicationHost(System.T
ype.GetType("mscoree.CorRuntimeHostClass"),"CRExample","c:\\Inetpub\\www
root\\CRExample");
//System.AppDomain.CreateDomain(CheckBoxList1.Items[iIndx].Value
,NE,NADS ) ;
}
break;
}
}
dom = null;
ad = null;
}
host.CloseEnum( enumHandle );
int refctr = Marshal.ReleaseComObject( host );
host = null;

GetAllDomains();
}
private void GetAllDomains()
{
this.CheckBoxList1.Items.Clear ();

mscoree.CorRuntimeHostClass host = new mscoree.CorRuntimeHostClass();

IntPtr enumHandle = IntPtr.Zero;
host.EnumDomains( out enumHandle );
object dom = null;
while(true)
{
host.NextDomain( enumHandle, out dom );
if( dom == null )
break;
AppDomain ad = (AppDomain) dom;
dom = null;
ListItem oLI = new ListItem(ad.FriendlyName,ad.FriendlyName);
CheckBoxList1.Items.Add ( oLI);
//Response.Write ( ad.FriendlyName + "<br>");

//try
//{
// Assembly[] allAsm = ad.GetAssemblies();
//
// foreach( Assembly asm in allAsm )
// Response.Write( " -->" + asm.FullName + "<br>" );
//}
//catch (Exception err)
//{
// Response.Write(err.Message + "<br>" );
//}
//
ad = null;
}
host.CloseEnum( enumHandle );
int refctr = Marshal.ReleaseComObject( host );
host = null;

}

private void CheckBoxList1_SelectedIndexChanged(object sender,
System.EventArgs e)
{

}
}
}


Natty Gur, CTO
Dao2Com Ltd.
28th Baruch Hirsch st. Bnei-Brak
Israel , 51114

Phone Numbers:
Office: +972-(0)3-5786668
Fax: +972-(0)3-5703475
Mobile: +972-(0)58-888377

Know the overall picture
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,078
Messages
2,570,572
Members
47,204
Latest member
MalorieSte

Latest Threads

Top