Querying IISMimeMap .. Access is denied .. HELP!

Discussion in 'ASP .Net' started by Marlon, Jul 22, 2004.

  1. Marlon

    Marlon Guest

    Code posted below ( I am not sure which group to post to, but I need help)

    I wrote a Windows Form Application to query the IIS MimeMap on the localhost
    which worked fine.

    I ran the same code in asp.net and got "Access is Denied" exception.

    What is the least permissions set I should grant the aspnet account to avoid
    the exception.
    Or any other suggest would be fine

    Thanks.

    Private Function CacheMimeMaps() As Specialized.StringDictionary

    #If DEBUG Then

    Dim starttime As DateTime = DateTime.Now

    #End If

    Dim entry As DirectoryServices.DirectoryEntry

    Try

    Dim mimeMaps As New Specialized.StringDictionary

    entry = New DirectoryServices.DirectoryEntry("IIS://localhost/MimeMap")

    Dim pvcMimeMap As DirectoryServices.PropertyValueCollection =
    entry.Properties("MimeMap")

    For Each o As Object In pvcMimeMap

    Dim mt As IISOle.IISMimeType = CType(o, IISOle.IISMimeType)

    mimeMaps.Add(mt.Extension, mt.MimeType)

    #If DEBUG Then

    Console.WriteLine("{0} = {1}", mt.Extension, mt.MimeType)

    #End If

    Next

    ' MimeMaps were found

    If mimeMaps.Count > 0 Then

    Me.Cache.Add(MIMEMAP, mimeMaps, Nothing, Cache.NoAbsoluteExpiration,
    Cache.NoSlidingExpiration, Caching.CacheItemPriority.Low, Nothing)

    Return mimeMaps

    End If

    pvcMimeMap = Nothing

    Catch ex As Exception ' do nothing

    Stop

    Finally

    #If DEBUG Then

    Dim endtime As DateTime = DateTime.Now

    Console.WriteLine(starttime.ToString() & "." &
    starttime.Millisecond.ToString())

    Console.WriteLine(endtime.ToString() & "." & endtime.Millisecond.ToString())

    #End If

    If (Not entry Is Nothing) Then

    entry.Close()

    entry.Dispose()

    End If

    End Try

    End Function
    Marlon, Jul 22, 2004
    #1
    1. Advertising

  2. Access is denied because only admins can run that code.
    By default, your code runs under a process for IIS that has no
    administrative rights.

    --
    compatible web farm Session replacement for Asp and Asp.Net
    http://www.nieropwebconsult.nl/asp_session_manager.htm

    "Marlon" <> wrote in message
    news:%23Nv%...
    > Code posted below ( I am not sure which group to post to, but I need
    > help)
    >
    > I wrote a Windows Form Application to query the IIS MimeMap on the
    > localhost
    > which worked fine.
    >
    > I ran the same code in asp.net and got "Access is Denied" exception.
    >
    > What is the least permissions set I should grant the aspnet account to
    > avoid
    > the exception.
    > Or any other suggest would be fine
    >
    > Thanks.
    >
    > Private Function CacheMimeMaps() As Specialized.StringDictionary
    >
    > #If DEBUG Then
    >
    > Dim starttime As DateTime = DateTime.Now
    >
    > #End If
    >
    > Dim entry As DirectoryServices.DirectoryEntry
    >
    > Try
    >
    > Dim mimeMaps As New Specialized.StringDictionary
    >
    > entry = New DirectoryServices.DirectoryEntry("IIS://localhost/MimeMap")
    >
    > Dim pvcMimeMap As DirectoryServices.PropertyValueCollection =
    > entry.Properties("MimeMap")
    >
    > For Each o As Object In pvcMimeMap
    >
    > Dim mt As IISOle.IISMimeType = CType(o, IISOle.IISMimeType)
    >
    > mimeMaps.Add(mt.Extension, mt.MimeType)
    >
    > #If DEBUG Then
    >
    > Console.WriteLine("{0} = {1}", mt.Extension, mt.MimeType)
    >
    > #End If
    >
    > Next
    >
    > ' MimeMaps were found
    >
    > If mimeMaps.Count > 0 Then
    >
    > Me.Cache.Add(MIMEMAP, mimeMaps, Nothing, Cache.NoAbsoluteExpiration,
    > Cache.NoSlidingExpiration, Caching.CacheItemPriority.Low, Nothing)
    >
    > Return mimeMaps
    >
    > End If
    >
    > pvcMimeMap = Nothing
    >
    > Catch ex As Exception ' do nothing
    >
    > Stop
    >
    > Finally
    >
    > #If DEBUG Then
    >
    > Dim endtime As DateTime = DateTime.Now
    >
    > Console.WriteLine(starttime.ToString() & "." &
    > starttime.Millisecond.ToString())
    >
    > Console.WriteLine(endtime.ToString() & "." &
    > endtime.Millisecond.ToString())
    >
    > #End If
    >
    > If (Not entry Is Nothing) Then
    >
    > entry.Close()
    >
    > entry.Dispose()
    >
    > End If
    >
    > End Try
    >
    > End Function
    >
    >
    >
    >
    Egbert Nierop \(MVP for IIS\), Jul 22, 2004
    #2
    1. Advertising

  3. Marlon

    Roger Bavaud Guest

    You can try to work with Impersonation
    http://support.microsoft.com/default.aspx?scid=kb;en-us;306158

    Regards
    Roger


    "Marlon" <> wrote in message
    news:%23Nv%...
    > Code posted below ( I am not sure which group to post to, but I need

    help)
    >
    > I wrote a Windows Form Application to query the IIS MimeMap on the

    localhost
    > which worked fine.
    >
    > I ran the same code in asp.net and got "Access is Denied" exception.
    >
    > What is the least permissions set I should grant the aspnet account to

    avoid
    > the exception.
    > Or any other suggest would be fine
    >
    > Thanks.
    >
    > Private Function CacheMimeMaps() As Specialized.StringDictionary
    >
    > #If DEBUG Then
    >
    > Dim starttime As DateTime = DateTime.Now
    >
    > #End If
    >
    > Dim entry As DirectoryServices.DirectoryEntry
    >
    > Try
    >
    > Dim mimeMaps As New Specialized.StringDictionary
    >
    > entry = New DirectoryServices.DirectoryEntry("IIS://localhost/MimeMap")
    >
    > Dim pvcMimeMap As DirectoryServices.PropertyValueCollection =
    > entry.Properties("MimeMap")
    >
    > For Each o As Object In pvcMimeMap
    >
    > Dim mt As IISOle.IISMimeType = CType(o, IISOle.IISMimeType)
    >
    > mimeMaps.Add(mt.Extension, mt.MimeType)
    >
    > #If DEBUG Then
    >
    > Console.WriteLine("{0} = {1}", mt.Extension, mt.MimeType)
    >
    > #End If
    >
    > Next
    >
    > ' MimeMaps were found
    >
    > If mimeMaps.Count > 0 Then
    >
    > Me.Cache.Add(MIMEMAP, mimeMaps, Nothing, Cache.NoAbsoluteExpiration,
    > Cache.NoSlidingExpiration, Caching.CacheItemPriority.Low, Nothing)
    >
    > Return mimeMaps
    >
    > End If
    >
    > pvcMimeMap = Nothing
    >
    > Catch ex As Exception ' do nothing
    >
    > Stop
    >
    > Finally
    >
    > #If DEBUG Then
    >
    > Dim endtime As DateTime = DateTime.Now
    >
    > Console.WriteLine(starttime.ToString() & "." &
    > starttime.Millisecond.ToString())
    >
    > Console.WriteLine(endtime.ToString() & "." &

    endtime.Millisecond.ToString())
    >
    > #End If
    >
    > If (Not entry Is Nothing) Then
    >
    > entry.Close()
    >
    > entry.Dispose()
    >
    > End If
    >
    > End Try
    >
    > End Function
    >
    >
    >
    >
    Roger Bavaud, Jul 22, 2004
    #3
    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. Mark
    Replies:
    0
    Views:
    316
  2. Marlon
    Replies:
    0
    Views:
    460
    Marlon
    Jul 22, 2004
  3. VJ
    Replies:
    4
    Views:
    435
    Dimitre Novatchev
    Nov 7, 2003
  4. Marlon
    Replies:
    1
    Views:
    112
    Egbert Nierop \(MVP for IIS\)
    Jul 22, 2004
  5. tabonni
    Replies:
    1
    Views:
    280
    Ray Costanzo [MVP]
    Oct 14, 2004
Loading...

Share This Page