Steve Schofield's Blog

September 2006 - Posts

  • Peek into Operations Magic on Microsoft.com Blog, Webcasts, and Whitepapers on IIS.NET

    This is a "great" article published on http://www.iis.net

    http://www.iis.net/News/Item.aspx?i=1191

    Check it out!

    Share this post: Email it! | bookmark it! | digg it! | reddit!
  • How-to display a "Friendly Name" when using CDOSYS in a script.

    This tip shows how to have a return address display with a friendly name instead of an email address. 

     

    How to use in a VBS script

     

    Dim imsg

     

    Set iMsg = Createobject("cdo.message")

     

    With iMsg

     

       .To = "John Monday <something@changeme.com>"

     

       .From = "Steve Friday <something@changeme.com>"

     

       .Subject = "A Subject Line: " & Now()

     

       .TextBody = "A Text body message"

     

    .Send

     

    End With

     

    Set iMsg = nothing

     

     

    Here is how to use in Classic ASP webpage.

     

    <%

    Dim imsg
    Dim strMessage

    Set iMsg = Server.Createobject("cdo.message")

     

    With iMsg

     

       .To = "John Monday <something@changeme.com>"

     

       .From = "Steve Friday <something@changeme.com>"

     

       .Subject = "A Subject Line: " & Now()

     

       .TextBody = "A Text body message"

     

    .Send

     

    End With

     

    Set iMsg = nothing

    strMessage = “Message sent:” & Now()

     

    %>

     

    <html>

                <body>

                            <% = strMessage %>

                </body>

    </html>



    Reference links

    ·        http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wss/wss/_exch2k_cdo_for_exchange_2000_server_objects.asp

    ·        http://msdn.microsoft.com/library/default.asp?url=/library/en-us/exchanchor/htms/msexchsvr_cdo_top.asp

    Share this post: Email it! | bookmark it! | digg it! | reddit!
  • Schedule a task to call a webpage using Task scheduler.

    One frequent question I see in the newsgroups is "How do I schedule a task to run in IIS?”   This article discusses one technique using a VBS Script and Windows Task Scheduler.    Using Windows Task scheduler allows custom jobs to execute without having to stay logged into a server.    You can use this technique to request web pages frequently on a timed basis.  This keeps the page in-memory providing a better performance.   This could also request web pages to perform other administrative tasks. 

    Here are steps to get started.

    • Write your VBS Script
    • Develop the webpage to process the HTTP Request
    • Create / Add table to database to track logging
    • Schedule the VBS Script

    Write your VBS script

    The script makes an HTTP request to a webpage on a timed basis.  (I.E. every 5 minutes).

    Call LogEntry()

    Sub LogEntry()

            ‘Force the script to finish on an error.
            On Error Resume Next

            'Declare variables
            Dim objRequest
            Dim URL

            Set objRequest = CreateObject("Microsoft.XMLHTTP")

           
    'Put together the URL link appending the Variables.
            URL = "http://www.YourDomain.com/track.aspx

            'Open the HTTP request and pass the URL to the objRequest object
            objRequest.open "POST", URL , false

           
    'Send the HTML Request
            objRequest.Send

            'Set the object to nothing
            Set objRequest = Nothing

    End Sub
     
    Track.aspx webpage

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="tracklog.aspx.vb" Inherits="Tracklog" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >

    <head runat="server">
        <title>Log Page</title>
    </head>

    <body>

    <form id="form1" runat="server">

    <div></div>

    </form>

    </body>

    </html>

    Tracklog.aspx.vb code behind

    Imports System.Data
    Imports System.Data.SqlClient
    Imports System.Configuration

    Partial Class Tracklog

        Inherits System.Web.UI.Page

            Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    ‘Put your code in that would process when Track.aspx is requested
           Response.write(“Track.aspx was called:” & System.DateTime.Now())

           End Sub

    End Class


    How to schedule a task using Windows Task Scheduler

    A scheduled task will allow a person to schedule any script, program, or document to run.   Scheduled Tasks run at the time specified which could be multiple times per minute, hour, or day.  The KB Article explains step-by-step.

    ·        http://support.microsoft.com/default.aspx?scid=kb;en-us;308569&sd=tech

    Refererence links

    Share this post: Email it! | bookmark it! | digg it! | reddit!
  • IIS7 interviews on Channel9

    This is worth watching if you are interested in learning more about IIS7.

    (Ken Schaefer (IIS MVP) and Chewy Chong)
    http://channel9.msdn.com/Showpost.aspx?postid=233984 

    Several videos by the Channel gang regarding IIS7.
    http://channel9.msdn.com/tags/IIS

    Share this post: Email it! | bookmark it! | digg it! | reddit!
  • SMTPDiag - troubleshooting email issues

    SMTPDiag is a handy tool for tracking down SMTP based issues.  I recently used in a newsgroup posting that was helpful along with a few other times at http://www.orcsweb.com.   It is definitely one of those tools worth having if you have to troubleshoot email issues. 

    Share this post: Email it! | bookmark it! | digg it! | reddit!
  • Use Logparser to extract information from a remote server application event log.

    I was recently extracting information from an application event log for a particular issue.  Using Logparser made it very simple to just get what I needed.  Hope this helps.

    'Extracts information for 'mydomain.com' and puts in a file called filename.csv

    LogParser "SELECT SourceName,TimeGenerated,TimeWritten,Message INTO filename.csv FROM \\Server\Application where Message Like '%mydomain.com%'" -o:CSV

    Share this post: Email it! | bookmark it! | digg it! | reddit!
  • Installing Dotnetnuke 4.x on Windows 2003 w/SP1 domain controller - update

    I wrote an article how to install Dotnetnuke 4.x on a Windows 2003 SP 1 domain controller.  Here is a "gotcha" I wanted to pass along thanks to Michael J. van Zwieten.   Thanks a bunch for passing this along.  I updated the article.  Here is Michaels comments.

    -------------------------------------

    I finally found an article that worked for me...

    Specifically this part:

    After many hours of looking for the problem I discovered that when you use the configuration editors for asp.net 2.x they add an attribute to the configuration element of the web.config file.

    ( xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0" )

    I removed the Attribute and ran the website once again and much to my surprise the website compiled and ran all the installation scripts.

    -------------------------------------

    Here is the link to my original article. 
    http://www.iislogs.com/articles/dnnonw2k3dc/default.aspx

    Steve Schofield
    Windows Server MVP - IIS
    ASPInsider Member - MCP

    http://www.orcsweb.com/
    Managed Complex Hosting
    #1 in Service and Support
    Share this post: Email it! | bookmark it! | digg it! | reddit!
  • IIS7 - post #9 - Reading MIME Types w/code

    I try to visit as many IIS7 places as possible.  One item mentioned not in the IIS7 GUI is how to add MIME types.  Well, I couldn't figure how to add them but I can 'read' them from my Vista RC1 machine.  How to add will be in another posting.  This code below doesn't build a list, but gives the basics for reading the values stored in the applicationHost.config file.  Happy IIS7 geeking!

    Dim sm As New Microsoft.Web.Administration.ServerManager()
    Dim appHostConfig As Configuration = sm.GetApplicationHostConfiguration()
    Dim section As ConfigurationSection = appHostConfig.GetSection("system.webServer/staticContent")

    For Each element As ConfigurationElement In section.GetCollection()
            Dim fileExtension As String = element.Item("fileExtension").ToString
           
    Dim mimeType As String = element.Item("mimeType").ToString
    Next

     

    For Each element As ConfigurationElement In section.GetCollection()
            Dim fileExtension As String = element.Item("fileExtension").ToString
           
    Dim mimeType As String = element.Item("mimeType").ToString
    Next

     

    For Each element As ConfigurationElement In section.GetCollection()
            Dim fileExtension As String = element.Item("fileExtension").ToString
           
    Dim mimeType As String = element.Item("mimeType").ToString
    Next

     

    For Each element As ConfigurationElement In section.GetCollection()
            Dim fileExtension As String = element.Item("fileExtension").ToString
           
    Dim mimeType As String = element.Item("mimeType").ToString
    Next

     

    Share this post: Email it! | bookmark it! | digg it! | reddit!
  • Vista RC1, IIS7 - Microsoft.Web.Administration code samples

    I installed Vista RC1 / 5600 edition and have been experimenting with the Microsoft.Web.Administration namespace. These are examples I got working on my local machine running Vista Ultimate Edition. Hope these help. If you find a more efficient way, by all means pass them along! These are my first attempt to understand and learn the new Microsoft.Web.Administration Namespace.

    'Create a new site called SteveSchofield.net
    Dim objSite As New Microsoft.Web.Administration.ServerManager
    objSite.Sites.Add("SteveSchofield.net", "c:\domains\steveschofield.net", 80)
    objSite.Sites("SteveSchofield.net").ServerAutoStart = True
    objSite.CommitChanges()

    'Add an ManagedPipelineMode.Integrated application pool
    Dim objAppPool As New Microsoft.Web.Administration.ServerManager
    objAppPool.ApplicationPools.Add("SteveSchofield.net")
    objAppPool.ApplicationPools("SteveSchofield.net").ManagedPipelineMode = ManagedPipelineMode.Integrated
    objAppPool.ApplicationPools("SteveSchofield.net").AutoStart = True
    objAppPool.CommitChanges()

    'Add an ManagedPipelineMode.Classic application pool
    Dim objAppPool As New Microsoft.Web.Administration.ServerManager
    objAppPool.ApplicationPools.Add("SteveSchofield.net")
    objAppPool.ApplicationPools("SteveSchofield.net").ManagedPipelineMode = ManagedPipelineMode.Classic
    objAppPool.ApplicationPools("SteveSchofield.net").AutoStart = True
    objAppPool.CommitChanges()

    'Create a Site, Application Pool (ManagedPipelineMode.Integrated) and add new site to the new App pool that was just created.
    Dim objSite As New Microsoft.Web.Administration.ServerManager
    objSite.Sites.Add("SteveSchofield.net", "c:\domains\steveschofield.net", 80)
    objSite.ApplicationPools.Add("SteveSchofield.net").ManagedPipelineMode = ManagedPipelineMode.Integrated
    objSite.Sites("SteveSchofield.net").Applications("/").ApplicationPoolName = "SteveSchofield.net"
    objSite.CommitChanges()

    'Create a Site, Application Pool (ManagedPipelineMode.Classic) and add new site to the new App pool that was just created.
    Dim objSite As New Microsoft.Web.Administration.ServerManager
    objSite.Sites.Add("SteveSchofield.net", "c:\domains\steveschofield.net", 80)
    objSite.ApplicationPools.Add("SteveSchofield.net").ManagedPipelineMode = ManagedPipelineMode.Classic
    objSite.Sites("SteveSchofield.net").Applications("/").ApplicationPoolName = "SteveSchofield.net"
    objSite.CommitChanges()

    'List application pools using IIS7 namespace
    Dim Server As New Microsoft.Web.Administration.ServerManager
    Dim col As ApplicationPoolCollection
    Dim AppPoolName as string
    Dim x as integer

    col = Server.ApplicationPools

    For x = 0 To col.Count - 1
     AppPoolName = col(x).Name
    Next

    'List sites using IIS7 namespace
    Dim Server As New Microsoft.Web.Administration.ServerManager
    Dim col As SiteCollection
    Dim SiteName as string
    Dim x as integer

    col = Server.Sites

    For x = 0 To col.Count - 1
     SiteName = col(x).Name
    Next

    'List all worker processes using IIS7 namespace. (Note this is just an example, there are other properties that can retrieve information about worker processes).
    Dim Server As New Microsoft.Web.Administration.ServerManager
    Dim col As Microsoft.Web.Administration.WorkerProcessCollection
    col = Server.WorkerProcesses
    dim x as integer
    For x = 0 To col.Count - 1
     Response.Write(col.Item(x).ApplicationDomains(x).Id & "<BR>")
     Response.Write(col.Item(x).ApplicationDomains(x).Idle & "<BR>")
     Response.Write(col.Item(x).ApplicationDomains(x).PhysicalPath & "<BR>")
     Response.Write(col.Item(x).ApplicationDomains(x).VirtualPath & "<BR>")
     Response.Write(col.Item(x).ApplicationDomains(x).WorkerProcess.ProcessGuid & "<BR>")
    Next

    'Recycle Application Pool
    Dim RecycleSite As New ServerManager
    RecycleSite.ApplicationPools("SteveSchofield.net").Recycle()

    'WebPages to help test if recycle actually worked.
    Place all webpages in the http://localhost website running IIS7
    Create webpage called Default.aspx
    Create webpage called Recycle.aspx
    Create webpage called Recycle.aspx.vb
    Paste the code listed below for the 'Default.aspx webpage
    Paste the code listed below for the Recycle.aspx webpage
    Paste the code listed below for the Recycle.aspx.vb webpage

    'Test out the process
    Open http://localhost/default.aspx?id=Show
    This will output the datetime session variable to the webpage
    Change the URL to http://localhost/default.aspx?id=Hide
    Refresh the webpage, the Session variable won't change
    Run the RecycleSite code in a separate webpage
    Refresh the default.aspx webpage
    The default.aspx webpage should not show any values

    'Default.aspx to show session variable
    <html>
    <body>
     <% If Request.Querystring("ID") = "Show" Then %>
      <% Session("Steve") = System.DateTime.Now() %>
     <% End If %>

     <% response.write(Session("Steve")) %>
    </body>
    </html>

    'Recycle.aspx webpage
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>Untitled Page</title>
    </head>
      <body>
      <form id="form1" runat="server">
     <div>
      Click Button to recycle<br /><br />
      <asp:Button ID="Button2" runat="server" Text="Button" />&nbsp;</div>
     </form>
      </body>
    </html>

    'Recycle.aspx.vb code behind file
    Imports Microsoft.Web.Administration
    Partial Class _Default
    System.Web.UI.Page

    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click

     Dim RecycleSite As New ServerManager
     RecycleSite.ApplicationPools("SteveSchofield.net").Recycle()

    End Sub
    End Class

    Share this post: Email it! | bookmark it! | digg it! | reddit!
  • IIS7, Vista RC1 and Microsoft.Web.Administration sample code

    I tried to post the code samples in my blog but for some reason the Community Server editor wasn't liking it.  Here is a link to the code.  http://www.iislogs.com/articles/21/

     

    Share this post: Email it! | bookmark it! | digg it! | reddit!
  • IIS7 - post #8

    Here is sample code to return a collection of Application Pools using WMI and IIS7.  This is pretty dynamic because this could be used to retrieve from a local machine or altering the code to connect to a remote machine running IIS7.

    'Define the WMI connection information
    Dim options As New System.Management.ConnectionOptions()
    'options.Username = strUID
    'options.Password = strPWD

    'Define the Scope information / Note the path defined.
    Dim scope As System.Management.ManagementScope
    scope =
    New System.Management.ManagementScope(\\.\root\WebAdministration)

    'Define Query and Searcher objects
    Dim WMIQuery As New System.Management.SelectQuery("SELECT * FROM ApplicationPool")
    Dim searcher As New System.Management.ManagementObjectSearcher(scope, WMIQuery)

    'Connect to WMI
    Try
           scope.Connect()
    Catch ex As Exception
           Exit Sub
    End Try

    'Dim variables for information that will be returned
    Dim AppPoolName As System.Management.ManagementObject
    Dim col As System.Management.ManagementObjectCollection

    'Return the collection
    col = searcher.Get()

    'Write the list of Application Pools to webpage
    For Each AppPoolName In col
           Response.Write(AppPoolName.GetPropertyValue(
    "Name").ToString() & "<BR>")
    Next


    Here is the IIS7'ish way of using the Microsoft.Web.Administration on a local machine.  I'm still trying to figure out how to use this new IIS7 namespace to connect to a remote machine.

            Dim Server As New Microsoft.Web.Administration.ServerManager  
            Dim col As ApplicationPoolCollection

            col = Server.ApplicationPools

            Dim AppPoolName As String = ""
            Dim x As Integer
           
            For x = 0 To col.Count - 1
                AppPoolName = col(x).Name
            Next
    Share this post: Email it! | bookmark it! | digg it! | reddit!
  • IIS7 - post #7

    Here is a good article I came across on MSDN / IIS7.  It was written in July 2006. 

    Extending IIS7 Runtime Infrastructure and Management Components
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dniis/html/iis7run.asp

    Summary: This article demonstrates how you can leverage the modular architecture of Internet Information Server 7.0 (IIS7) to extend the functionality of the core Web server. In addition, it takes advantage of new management service and tool extensibility features to create a compelling sample solution that increases the Web server feature set.

    Share this post: Email it! | bookmark it! | digg it! | reddit!
  • Vista RC1 and IIS7

    I installed Vista RC1 / 5600 edition and have been experimenting with the Microsoft.Web.Administration namespace.  I'll update this post with other quick examples. 

    'Create a new site called SteveSchofield.net
    Dim
    objSite As New Microsoft.Web.Administration.ServerManager
    objSite.Sites.Add(
    "SteveSchofield.net", "c:\domains\steveschofield.net", 80)
    objSite.Sites(
    "SteveSchofield.net").ServerAutoStart = True
    objSite.CommitChanges()

    '

    Share this post: Email it! | bookmark it! | digg it! | reddit!
  • IIS7 - post #6

    Looking at the appcmd.exe utility lately in IIS7?  If not, here is a good article http://www.iis.net/default.aspx?tabid=2&subtabid=25&i=954.   I was also trying to review all the 'objects' and what each of them would do.   I found an XML file called 'appcmd.xml' in C:\Windows\System32\inetsrv which is a nice GUI to display all objects instead of typing out the commands. This opened in IE for me.  I'm all for command line power and ease of use.  To get familar quickly, reviewing the appcmd.XML file make it quicker.  I recommend checking it out.
    Share this post: Email it! | bookmark it! | digg it! | reddit!
  • IIS7 - post #5

    This is a plug for the IIS7 forums on http://www.iis.net.  Here is a link http://forums.iis.net/default.aspx?GroupID=41   As RC1 of vista and others are around the corner.  IIS7 is going to become real popular!
    Share this post: Email it! | bookmark it! | digg it! | reddit!

Powered by Community Server 2.1