The process aspnet_wp is a surviver !

Ask a Question related to ASP.NET Security, Design and Development.

  1. #1

    Default The process aspnet_wp is a surviver !

    Hi. I am trying to use a treeview - after a few attempts, it works, but only
    up to a point - my exercise was to dynamically create nodes in the treeview.
    I read about binding the treeview to a XML file. Okay, so I decided to
    complicate my exercise and to create the XML file on the fly. I am using
    this code to browse through the list of my other projects, create the XML
    file and then populate the treeview. I am not using the XML writer object
    because I did not reach that point with my learning, so I am writing it "the
    old way":

    <code>
    Private m_strPath As String = "C:\Documents and
    Settings\Administrator\My Documents\My
    Projects\ASPNETProjects\vsnet\ThirdPartyControls\T reeNodes.XML"

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load
    If Not IsPostBack Then
    CreateXMLFile()
    TreeView1.TreeNodeSrc = m_strPath
    TreeView1.DataBind()
    End If
    End Sub

    Private Sub CreateXMLFile()

    Dim objDirectory As Directory
    Dim ProjectInfo As FileInfo

    Dim lstFiles As String()
    Dim strProjectLongName As String
    Dim strProjectShortName As String

    Dim strmFile As StreamWriter
    Dim objStringBuilder As New StringBuilder()

    Const PROJECTS_PATH As String = "C:\Documents and
    Settings\Administrator\My Documents\My Projects\ASPNETProjects\notepad\"

    strmFile = File.CreateText(m_strPath)
    strmFile.WriteLine("<TREENODES>")
    strmFile.WriteLine("<TREENODE TEXT=""ASP.NET PROJECTS"">")

    lstFiles = objDirectory.GetFiles(PROJECTS_PATH, "*.aspx")
    For Each strProjectLongName In lstFiles
    ProjectInfo = New FileInfo(strProjectLongName)
    strProjectShortName = ProjectInfo.Name
    objStringBuilder = New StringBuilder()
    objStringBuilder.Append("<TREENODE TEXT=""" &
    strProjectShortName & """ NAVIGATEURL =
    ""HTTP:\\LOCALHOST\ASPNETPROJECTS\NOTEPAD\")
    objStringBuilder.Append(strProjectShortName)
    objStringBuilder.Append("""" & "/>")
    strmFile.WriteLine(objStringBuilder.ToString)
    Next strProjectLongName

    strmFile.WriteLine("</TREENODE>")
    strmFile.Write("</TREENODES>")
    strmFile.Flush()

    strmFile.Close()
    strmFile = Nothing
    objStringBuilder = Nothing
    lstFiles = Nothing
    objDirectory = Nothing
    End Sub
    </code>

    This code works fine, but ... if I run the application one more time, I get:
    ________________________________________________
    Exception Details: System.IO.IOException: The process cannot access the file
    "C:\Documents and Settings\Administrator\My Documents\My
    Projects\ASPNETProjects\vsnet\ThirdPartyControls\T reeNodes.XML" because it
    is being used by another process.
    ________________________________________________

    I also discovered that I can't even delete the "TreeNodes.XML" file IN
    EXPLORER (!) because the file is locked.. VERY STRANGE - this happens EVEN
    if I close VS.NET !

    I discovered that the only way out is to kill the process "aspnet_wp" in
    task manager - it gets recreated instantly, even with VS.NET closed (!?),
    but at least I can now delete the file in Explorer. So the sequence to make
    it work is this: run the app the first time - stop it - kill the aspnet_wp
    process (it gets recreated) - now I can run the app again without having the
    above-mentioned error.

    What's with this lock ??? Am I doing something wrong in this code ? I even
    set to nothing almost all objects in my app, except the strings, even if
    this is useless....

    Thank you.
    Alex.


    news.iq.ca Guest

  2. Similar Questions and Discussions

    1. Must manually attach to ASPNET_WP process to debug ASP.NET code
      We're using Visual Studio 2003 .NET (C#) on Windows XP Pro SP2. We have a smart client (WinForms) application that calls an ASP.NET web service. On...
    2. aspnet_wp process recycles itself
      Hi, We have a webservice in c# which makes use of XML and COM objects. The MemoryLimit in processModel in machine.config is set to the default of...
    3. worker process aspnet_wp.exe identity
      If the woker process is configured to be run under username="machine" in machine.config and impersonate=true under web.config, will the impersonated...
    4. debugger not automatically attaching aspnet_wp.exe as a debugged process
      Hi-- All of sudden (?) the VS.NET v1 IDE is NOT automatically attaching aspnet_wp.exe as a debugged process. Why? Here is the situation. ...
    5. Unloading web application instance w/o trashing aspnet_wp process
      I have a simple question for the right person, is there a way to unload an application (the resources held by a single virtual directory) from some...
  3. #2

    Default Re: The process aspnet_wp is a surviver !

    Alex,

    The aspnet_wp process is part of ASP.Net and is responsible for executing
    the code behind your page. Here's what I think is happening with the lock.
    When you set the TreeNodeSrc property and call DataBind method of the
    TreeView object the object open the XML file and doesn't close it. It seems
    that the TreeNodeSrc property can be assigned either a file name or directly
    the XML data as a System.String. You can try that to get around the issue
    with the lock.

    --
    Jiri Richter
    Microsoft Corp.

    This posting is provided "AS IS" with no warranties, and confers no rights.


    "news.iq.ca" <REMOVETHIScuca_macaii2000@yahoo.com> wrote in message
    news:41c12a17$1_4@aeinews....
    > Hi. I am trying to use a treeview - after a few attempts, it works, but
    > only up to a point - my exercise was to dynamically create nodes in the
    > treeview. I read about binding the treeview to a XML file. Okay, so I
    > decided to complicate my exercise and to create the XML file on the fly. I
    > am using this code to browse through the list of my other projects, create
    > the XML file and then populate the treeview. I am not using the XML writer
    > object because I did not reach that point with my learning, so I am
    > writing it "the old way":
    >
    > <code>
    > Private m_strPath As String = "C:\Documents and
    > Settings\Administrator\My Documents\My
    > Projects\ASPNETProjects\vsnet\ThirdPartyControls\T reeNodes.XML"
    >
    > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    > System.EventArgs) Handles MyBase.Load
    > If Not IsPostBack Then
    > CreateXMLFile()
    > TreeView1.TreeNodeSrc = m_strPath
    > TreeView1.DataBind()
    > End If
    > End Sub
    >
    > Private Sub CreateXMLFile()
    >
    > Dim objDirectory As Directory
    > Dim ProjectInfo As FileInfo
    >
    > Dim lstFiles As String()
    > Dim strProjectLongName As String
    > Dim strProjectShortName As String
    >
    > Dim strmFile As StreamWriter
    > Dim objStringBuilder As New StringBuilder()
    >
    > Const PROJECTS_PATH As String = "C:\Documents and
    > Settings\Administrator\My Documents\My Projects\ASPNETProjects\notepad\"
    >
    > strmFile = File.CreateText(m_strPath)
    > strmFile.WriteLine("<TREENODES>")
    > strmFile.WriteLine("<TREENODE TEXT=""ASP.NET PROJECTS"">")
    >
    > lstFiles = objDirectory.GetFiles(PROJECTS_PATH, "*.aspx")
    > For Each strProjectLongName In lstFiles
    > ProjectInfo = New FileInfo(strProjectLongName)
    > strProjectShortName = ProjectInfo.Name
    > objStringBuilder = New StringBuilder()
    > objStringBuilder.Append("<TREENODE TEXT=""" &
    > strProjectShortName & """ NAVIGATEURL =
    > ""HTTP:\\LOCALHOST\ASPNETPROJECTS\NOTEPAD\")
    > objStringBuilder.Append(strProjectShortName)
    > objStringBuilder.Append("""" & "/>")
    > strmFile.WriteLine(objStringBuilder.ToString)
    > Next strProjectLongName
    >
    > strmFile.WriteLine("</TREENODE>")
    > strmFile.Write("</TREENODES>")
    > strmFile.Flush()
    >
    > strmFile.Close()
    > strmFile = Nothing
    > objStringBuilder = Nothing
    > lstFiles = Nothing
    > objDirectory = Nothing
    > End Sub
    > </code>
    >
    > This code works fine, but ... if I run the application one more time, I
    > get:
    > ________________________________________________
    > Exception Details: System.IO.IOException: The process cannot access the
    > file "C:\Documents and Settings\Administrator\My Documents\My
    > Projects\ASPNETProjects\vsnet\ThirdPartyControls\T reeNodes.XML" because it
    > is being used by another process.
    > ________________________________________________
    >
    > I also discovered that I can't even delete the "TreeNodes.XML" file IN
    > EXPLORER (!) because the file is locked.. VERY STRANGE - this happens EVEN
    > if I close VS.NET !
    >
    > I discovered that the only way out is to kill the process "aspnet_wp" in
    > task manager - it gets recreated instantly, even with VS.NET closed (!?),
    > but at least I can now delete the file in Explorer. So the sequence to
    > make it work is this: run the app the first time - stop it - kill the
    > aspnet_wp process (it gets recreated) - now I can run the app again
    > without having the above-mentioned error.
    >
    > What's with this lock ??? Am I doing something wrong in this code ? I even
    > set to nothing almost all objects in my app, except the strings, even if
    > this is useless....
    >
    > Thank you.
    > Alex.
    >

    Jiri Richter [MSFT] Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139