The process aspnet_wp is a surviver !

Discussion in 'ASP .Net Security' started by news.iq.ca, Dec 16, 2004.

  1. news.iq.ca

    news.iq.ca Guest

    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\TreeNodes.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\TreeNodes.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, Dec 16, 2004
    #1
    1. Advertising

  2. 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" <> 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\TreeNodes.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\TreeNodes.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], Dec 31, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. alien2_51
    Replies:
    0
    Views:
    552
    alien2_51
    Jun 27, 2003
  2. Mark Kamoski
    Replies:
    1
    Views:
    591
    Jim Cheshire [MSFT]
    Aug 5, 2003
  3. Luther Miller
    Replies:
    2
    Views:
    2,044
    Luther Miller
    Aug 27, 2003
  4. Sergey Numerov

    aspnet_wp process not running

    Sergey Numerov, May 6, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    2,014
    Alvin Bruney [MVP]
    May 10, 2004
  5. Robert W. Eckert
    Replies:
    4
    Views:
    788
    =?Utf-8?B?Um9iIEVja2VydA==?=
    Oct 5, 2004
Loading...

Share This Page