Shreeman's profileShreemanBlogLists Tools Help
    July 27

    Good Read on Asp.net And MEdium Trust

     
    Have you  ever consumed a FullTrust Assembly in another web application hosted in a webshare .If the answer is yes did u got a Security Exception while trying to consume the Fulltrust application in a partial trust Env? If your answer is YES again then you might be facing an issue with the LINKDEMAND .As usual I did  first digged msdn and then non other then Shwan's blog
    great place to understand the CAS related issue] and i found that many people have experienced similar issue and here is one post Where you find a detail Journey how it runed out to be a nightmare for the author  
    Another important point how you can specify the originator in the Config and this apply both to Click Once as well as any app runnign from a Network share is specifying the originator of the application .Anyway this is indeed a good experience and i ll suggest one should definitely go thru shawn's posts on these .

    COnfiguration Tool FOR WEBSITE and IIS MANAGEMENT:Part2

    In Part1 we see how we can Copy Folders between 2 different systems and How to create Site Programmatically thru c#.IN this Part we ll see how we can creat a VDIR and create a App Pool and How can we map the VDIR to App Pool and further if possible i ll show how you can create user,Roles and AMp the User,Roles to the permission list and Apppool:-
     

    using System.IO;

    using

    System.Management;

    using

    System.Management.Instrumentation;

    using

    System.DirectoryServices;

     

     

     

    CREATE A VIRTUALDIRECTORY:-

     

    #region

    virtual directory

    static void CreateVDir(string metabasePath, string vDirName, string physicalPath)

    {

    MessageBox.Show("\n Creating virtual directory , mapping the Root application to :"+ metabasePath +", \n Virtual Directory Name :" +vDirName+",\n physical path :"+physicalPath);

    try

    {

    DirectoryEntry site = new DirectoryEntry(metabasePath);

    string className = site.SchemaClassName.ToString();

    if ((className.EndsWith("Server")) || (className.EndsWith("VirtualDir")))

    {

    DirectoryEntries vdirs = site.Children;

    DirectoryEntry newVDir = vdirs.Add(vDirName, (className.Replace("Service", "VirtualDir")));

    newVDir.Properties["Path"][0] = physicalPath;

    newVDir.Properties["AccessScript"][0] = true;

    // These properties are necessary for an application to be created.

    newVDir.Properties["AppFriendlyName"][0] = vDirName;

    newVDir.Properties["AppIsolated"][0] = "1";

    newVDir.Properties["AppRoot"][0] = "/LM" + metabasePath.Substring(metabasePath.IndexOf("/", ("IIS://".Length)));

    newVDir.CommitChanges();

    MessageBox.Show(" Done.");

    }

    else

    MessageBox.Show(" Failed. A virtual directory can only be created in a site or virtual directory node.");

    }

    catch (Exception ex)

    {

    MessageBox.Show("Failed in CreateVDir with the following exception: "+ ex.Message);

    }

    }

    private void cmd_vdir_Click(object sender, System.EventArgs e)

    {

    //CreateVDir(@"IIS://Localhost/W3SVC/1/Root", "Virtual directory name here" , textBox2.Text);

    }

    #endregion

    virtual directory

     

     

    CREATE AN APPPOOL:-

     

    #region

    Apppool

    static void CreateAppPool(string metabasePath, string appPoolName)

    {

    // metabasePath is of the form "IIS://<servername>/W3SVC/AppPools"

    // for example "IIS://localhost/W3SVC/AppPools"

    // appPoolName is of the form "<name>", for example, "MyAppPool"

    MessageBox.Show("\nCreating application pool named :" + metabasePath +","+ appPoolName);

    try

    {

    if (metabasePath.EndsWith("/W3SVC/AppPools"))

    {

    DirectoryEntry newpool;

    DirectoryEntry apppools = new DirectoryEntry(metabasePath);

    newpool = apppools.Children.Add(appPoolName, "IIsApplicationPool");

    newpool.CommitChanges();

    MessageBox.Show(" Done.");

    }

    else

    MessageBox.Show(" Failed in CreateAppPool; application pools can only be created in the */W3SVC/AppPools node.");

    }

    catch (Exception ex)

    {

    MessageBox.Show("Failed in CreateAppPool with the following exception: \n{0}", ex.Message);

    }

    }

    private void cmd_apppool_Click(object sender, System.EventArgs e)

    {

    //CreateAppPool("IIS://Localhost/W3SVC/AppPools", "APP POOL NAME HERE");

    }

    #endregion Apppool

     

    MAP VDIR TO APPPOOL:-

     

    #region

    Assign VDIR TO AppPool

    static void AssignVDirToAppPool(string metabasePath, string appPoolName)

    {

    // metabasePath is of the form "IIS://<servername>/W3SVC/<siteID>/Root[/<vDir>]"

    // for example "IIS://localhost/W3SVC/1/Root/MyVDir"

    // appPoolName is of the form "<name>", for example, "MyAppPool"

    MessageBox.Show("\nAssigning application to the application pool named :"+ metabasePath+":"+ appPoolName);

    try

    {

    DirectoryEntry vDir =

    new DirectoryEntry(metabasePath);

    string className = vDir.SchemaClassName.ToString();

    if (className.EndsWith("VirtualDir"))

    {

    object[] param = { 0, appPoolName, true };

    vDir.Invoke("AppCreate3", param);

    vDir.Properties["AppIsolated"][0] = "2";

    MessageBox.Show(" Done.");

    }

    else

    MessageBox.Show(" Failed in AssignVDirToAppPool; only virtual directories can be assigned to application pools");

    }

    catch (Exception ex)

    {

    MessageBox.Show("Failed in AssignVDirToAppPool with the following exception: \n{0}", ex.Message);

    }

    }

    private void cmdVdirtoAppPool_Click(object sender, System.EventArgs e)

    {

    //AssignVDirToAppPool("IIS://Localhost/W3SVC/1/Root/virtualdirectorynamehere", "apppool name here");

    }

    #endregion

    Assign VDIR TO AppPool

     

    In NExt PArt :- I ll show how you ll create user,Roles and mapthe User,Roles to the permission list and Apppool:-

     

    COnfiguration Tool FOR WEBSITE and IIS MANAGEMENT:Part1

    I have Been Asked for a Demo[POC] for creating a simple Tool to create a Tool to Manage sites,AppPool and IIS :-
     
    Although this POC was long back implemented by me using VB script [WMI] ,I often see Questions in DL and USerGroups and NEwsGroup how to perform these in C#.Thus I thought I ll provide few C# Code[Not ProductionLEvel but for Demo] for this purpose .I foudn that i ca't quite remember what all functionality i had implemented but the parts of the same contains the folowing:-
     

    using System.IO;

    using System.Management;

    using System.Management.Instrumentation;

    using System.DirectoryServices;

     
    Copy Folder between 2 Different Systems Recursively [Remote Systems]:-
     
     if in same network if are apart then there are many FTP rotine available.Inside the same network you can use sometihing like :-
     
    We have 2 folderbrowser and 2 TextBox displaying the path or you can Type the path(for \\ specifically) into those TextBoxes.And a Copy Button to Start the Copy
     

    private

    void CmdSource_Browse_Click(object sender, System.EventArgs e)

    {

    folderBrowserDialog1.ShowDialog();

    textBox1.Text=folderBrowserDialog1.SelectedPath.ToString();

    }

    private void cmdDest_Broswe_Click(object sender, System.EventArgs e)

    {

    folderBrowserDialog1.ShowDialog();

    textBox2.Text=folderBrowserDialog1.SelectedPath.ToString();

    }

    #region

    copy

    private void copyfolder(string sourcedir,string destdir)

    {

    DirectoryInfo dirinfo=new DirectoryInfo(sourcedir);

    if(Directory.Exists(destdir)==false)

    {

    Directory.CreateDirectory(destdir);

    }

    foreach(FileSystemInfo fsinf in dirinfo.GetFileSystemInfos())

    {

    string destfilename=Path.Combine(destdir,fsinf.Name);

    if ( fsinf is FileInfo)

    {

    if (File.Exists(destfilename)==true)

    {

    if ((File.GetAttributes(destfilename) != FileAttributes.Normal))

    {

    File.SetAttributes(destfilename,FileAttributes.Normal);

    }

    }

    // Try to copy the file.

    File.Copy(fsinf.FullName,destfilename,true);

    }

    else

    {

    copyfolder(fsinf.FullName,destfilename);

    }

    }

    }

    private void cmd_copy_Click(object sender, System.EventArgs e)

    {

    if(Directory.Exists(textBox1.Text) && Directory.Exists(textBox2.Text))

    {

    copyfolder(textBox1.Text,textBox2.Text);

    MessageBox.Show("Completed");

    }

    else

    {

    MessageBox.Show("Creating the directory");

    copyfolder(textBox1.Text,textBox2.Text);

    MessageBox.Show("Completed");

    }

    }

    #endregion

    copy
     
     
    CREATE a SITE:-
     

    #region

    Site

    static void CreateSite(string metabasePath, string siteID, string siteName, string physicalPath)

    {

    // metabasePath is of the form "IIS://<servername>/<service>"

    // for example "IIS://localhost/W3SVC"

    // siteID is of the form "<number>", for example "555"

    // siteName is of the form "<name>", for example, "My New Site"

    // physicalPath is of the form "<drive>:\<path>", for example, "C:\Inetpub\Wwwroot"

    MessageBox.Show("\n Creating site , mapping the Root application to :"+ metabasePath+

    "/n ,"+ ",/n siteID :"+ siteID +

    "/n ,"+ "physicalPath:"+physicalPath);

    try

    {

    DirectoryEntry service = new DirectoryEntry(metabasePath);

    string className = service.SchemaClassName.ToString();

    if (className.EndsWith("Service"))

    {

    DirectoryEntries sites = service.Children;

    DirectoryEntry newSite = sites.Add(siteID, (className.Replace("Service", "Server")));

    newSite.Properties["ServerComment"][0] = siteName;

    newSite.CommitChanges();

    DirectoryEntry newRoot;

    newRoot = newSite.Children.Add("Root", "IIsWebVirtualDir");

    newRoot.Properties["Path"][0] = physicalPath;

    newRoot.Properties["AccessScript"][0] = true;

    newRoot.CommitChanges();

    MessageBox.Show(" Done. Your site will not start until you set the ServerBindings or SecureBindings property.");

    }

    else

    MessageBox.Show(" Failed. A site can only be created in a service node.");

    }

    catch (Exception ex)

    {

    MessageBox.Show("Failed in CreateSite with the following exception:/n"+ ex.Message);

    }

    }

    private void cmd_site_Click(object sender, System.EventArgs e)

    {

    string sitename="";

    helpdialog dialog = new helpdialog();

    // Show Dialog as a modal dialog and determine if DialogResult = OK.

    if (dialog.ShowDialog(this) == DialogResult.OK)

    {

    // Read the contents of testDialog's TextBox.

    sitename = dialog.Text;

    }

    else

    {

    sitename = "Cancelled";

    }

    dialog.Dispose();

    MessageBox.Show(sitename);

     

    //CreateSite("IIS://Localhost/W3SVC", "555", "Site name here", textBox2.Text);

    }

    #endregion

    Site

     

    IN PArt2:- We ll create a AppPoll and VDir and Assign the VDir to Apppool

     
    July 01

    NEXT GEN DATA ACCESS WHITEPAPAERS

    Microsoft has released White papers on the NEXT GEN DATA Access.whether its LINQ,DLINQ or BLINQ and XLINQ
    the next gen dataaccess is revolving around Entity model framework,ORM etc..; Thus without further Notes on the vast topic heer are the Links to the Entity framework Whitepapers