uploading images files problem

Posted on 2004-08-17
Last Modified: 2012-05-05
I'm trying to upload images files to a certain directory but I'm getting this error message. When I writeklick the images image and select properties I can't reach the security tab (it does not appear).
What can I do to fix the problem? Thank you

Here is the error message I'm getting:

Access to the path "c:\inetpub\wwwroot\Maklarna_5\bilder\31076036.jpeg" is denied.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.UnauthorizedAccessException: Access to the path "c:\inetpub\wwwroot\Maklarna_5\bilder\31076036.jpeg" is denied.

ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate="true"/>, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.

To grant ASP.NET write access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.

Source Error:

Line 86:
Line 87:             '
Line 88:             myFile.PostedFile.SaveAs(MapPath("bilder/") & strFileNameOnly)
Line 89:
Line 90:             Dim intFileNameLength1 As Integer

Source File: C:\Inetpub\wwwroot\Maklarna_5\admin_ny_objekt.aspx.vb    Line: 88

Stack Trace:

[UnauthorizedAccessException: Access to the path "c:\inetpub\wwwroot\Maklarna_5\bilder\31076036.jpeg" is denied.]
   System.IO.__Error.WinIOError(Int32 errorCode, String str) +393
   System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, Boolean bFromProxy) +888
   System.IO.FileStream..ctor(String path, FileMode mode) +52
   System.Web.HttpPostedFile.SaveAs(String filename) +48
   Maklarna_5.admin_ny_objekt.Submit(Object obj, EventArgs e) in C:\Inetpub\wwwroot\Maklarna_5\admin_ny_objekt.aspx.vb:88
   System.Web.UI.HtmlControls.HtmlInputButton.OnServerClick(EventArgs e) +108
   System.Web.UI.HtmlControls.HtmlInputButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +138
   System.Web.UI.Page.ProcessRequestMain() +1277

Here is my code behind code:

Imports System.Data.Odbc
Imports System.Configuration

Public Class admin_ny_objekt
    Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents lblMessage As System.Web.UI.WebControls.Label
    Protected WithEvents RequiredFieldValidator1 As System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents RequiredFieldValidator2 As System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents RequiredFieldValidator3 As System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents RequiredFieldValidator4 As System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents RequiredFieldValidator5 As System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents RequiredFieldValidator6 As System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents RequiredFieldValidator7 As System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents RequiredFieldValidator8 As System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents RequiredFieldValidator9 As System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents RequiredFieldValidator10 As System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents RequiredFieldValidator11 As System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents RequiredFieldValidator12 As System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents RequiredFieldValidator13 As System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents RequiredFieldValidator14 As System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents RequiredFieldValidator15 As System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents RequiredFieldValidator16 As System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents RequiredFieldValidator24 As System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents RequiredFieldValidator18 As System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents RequiredFieldValidator25 As System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents RequiredFieldValidator26 As System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents RequiredFieldValidator27 As System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents RequiredFieldValidator28 As System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents RequiredFieldValidator29 As System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents RequiredFieldValidator30 As System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents Button1 As System.Web.UI.HtmlControls.HtmlInputButton
    Protected WithEvents tbLan As System.Web.UI.HtmlControls.HtmlInputText
    Protected WithEvents tbAdress As System.Web.UI.HtmlControls.HtmlInputText
    Protected WithEvents tbKategori As System.Web.UI.HtmlControls.HtmlInputText
    Protected WithEvents tbBoyta As System.Web.UI.HtmlControls.HtmlInputText
    Protected WithEvents tbRum As System.Web.UI.HtmlControls.HtmlInputText
    Protected WithEvents tbAvgift As System.Web.UI.HtmlControls.HtmlInputText
    Protected WithEvents tbPris As System.Web.UI.HtmlControls.HtmlInputText
    Protected WithEvents tbFastighetsbeteckning As System.Web.UI.HtmlControls.HtmlInputText
    Protected WithEvents taBeskrivning As System.Web.UI.HtmlControls.HtmlTextArea
    Protected WithEvents taPlanlosning As System.Web.UI.HtmlControls.HtmlTextArea
    Protected WithEvents taByggnadssatt As System.Web.UI.HtmlControls.HtmlTextArea
    Protected WithEvents taPlanbestammelser As System.Web.UI.HtmlControls.HtmlTextArea
    Protected WithEvents taTomtbeskrivning As System.Web.UI.HtmlControls.HtmlTextArea
    Protected WithEvents taGarage As System.Web.UI.HtmlControls.HtmlTextArea
    Protected WithEvents taEkonomi As System.Web.UI.HtmlControls.HtmlTextArea
    Protected WithEvents taOvrigt As System.Web.UI.HtmlControls.HtmlTextArea
    Protected WithEvents myFile As System.Web.UI.HtmlControls.HtmlInputFile
    Protected WithEvents myFile1 As System.Web.UI.HtmlControls.HtmlInputFile
    Protected WithEvents myFile2 As System.Web.UI.HtmlControls.HtmlInputFile
    Protected WithEvents myFile3 As System.Web.UI.HtmlControls.HtmlInputFile
    Protected WithEvents myFile4 As System.Web.UI.HtmlControls.HtmlInputFile
    Protected WithEvents myFile5 As System.Web.UI.HtmlControls.HtmlInputFile
    Protected WithEvents myFile6 As System.Web.UI.HtmlControls.HtmlInputFile
    Protected WithEvents tbKommun As System.Web.UI.HtmlControls.HtmlInputText
    Protected WithEvents Button2 As System.Web.UI.HtmlControls.HtmlInputButton

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
    End Sub

#End Region

    Sub Submit(ByVal obj As Object, ByVal e As EventArgs)
        'If Not (myFile.PostedFile Is Nothing) Then
        If Page.IsValid Then

            Dim intFileNameLength As Integer
            Dim strFileNamePath As String
            Dim strFileNameOnly As String

            'Logic to find the FileName (excluding the path)
            strFileNamePath = myFile.PostedFile.FileName
            intFileNameLength = InStr(1, StrReverse(strFileNamePath), "\")
            strFileNameOnly = Mid(strFileNamePath, (Len(strFileNamePath) - intFileNameLength) + 2)

            'myFile.PostedFile.SaveAs("c:\ASPnet\upload\" & strFileNameOnly)
            myFile.PostedFile.SaveAs(MapPath("bilder/") & strFileNameOnly)

            Dim intFileNameLength1 As Integer
            Dim strFileNamePath1 As String
            Dim strFileNameOnly1 As String

            'Logic to find the FileName (excluding the path)
            strFileNamePath1 = myFile1.PostedFile.FileName
            intFileNameLength1 = InStr(1, StrReverse(strFileNamePath1), "\")
            strFileNameOnly1 = Mid(strFileNamePath1, (Len(strFileNamePath1) - intFileNameLength1) + 2)

            myFile1.PostedFile.SaveAs(MapPath("bilder2/") & strFileNameOnly1)

            Dim intFileNameLength2 As Integer
            Dim strFileNamePath2 As String
            Dim strFileNameOnly2 As String

            'Logic to find the FileName (excluding the path)
            strFileNamePath2 = myFile2.PostedFile.FileName
            intFileNameLength2 = InStr(1, StrReverse(strFileNamePath2), "\")
            strFileNameOnly2 = Mid(strFileNamePath2, (Len(strFileNamePath2) - intFileNameLength2) + 2)

            myFile2.PostedFile.SaveAs(MapPath("bilder2/") & strFileNameOnly2)

            Dim intFileNameLength3 As Integer
            Dim strFileNamePath3 As String
            Dim strFileNameOnly3 As String

            'Logic to find the FileName (excluding the path)
            strFileNamePath3 = myFile3.PostedFile.FileName
            intFileNameLength3 = InStr(1, StrReverse(strFileNamePath3), "\")
            strFileNameOnly3 = Mid(strFileNamePath3, (Len(strFileNamePath3) - intFileNameLength3) + 2)

            myFile3.PostedFile.SaveAs(MapPath("bilder2/") & strFileNameOnly3)

            Dim intFileNameLength4 As Integer
            Dim strFileNamePath4 As String
            Dim strFileNameOnly4 As String

            'Logic to find the FileName (excluding the path)
            strFileNamePath4 = myFile4.PostedFile.FileName
            intFileNameLength4 = InStr(1, StrReverse(strFileNamePath4), "\")
            strFileNameOnly4 = Mid(strFileNamePath4, (Len(strFileNamePath4) - intFileNameLength4) + 2)

            myFile4.PostedFile.SaveAs(MapPath("bilder2/") & strFileNameOnly4)

            Dim intFileNameLength5 As Integer
            Dim strFileNamePath5 As String
            Dim strFileNameOnly5 As String

            'Logic to find the FileName (excluding the path)
            strFileNamePath5 = myFile5.PostedFile.FileName
            intFileNameLength5 = InStr(1, StrReverse(strFileNamePath5), "\")
            strFileNameOnly5 = Mid(strFileNamePath5, (Len(strFileNamePath5) - intFileNameLength5) + 2)

            myFile5.PostedFile.SaveAs(MapPath("bilder2/") & strFileNameOnly5)

            Dim intFileNameLength6 As Integer
            Dim strFileNamePath6 As String
            Dim strFileNameOnly6 As String

            'Logic to find the FileName (excluding the path)
            strFileNamePath6 = myFile6.PostedFile.FileName
            intFileNameLength6 = InStr(1, StrReverse(strFileNamePath6), "\")
            strFileNameOnly6 = Mid(strFileNamePath6, (Len(strFileNamePath6) - intFileNameLength6) + 2)

            myFile6.PostedFile.SaveAs(MapPath("bilder2/") & strFileNameOnly6)

            Dim myConnection As OdbcConnection = New OdbcConnection(ConfigurationSettings.AppSettings("ConnectionString"))
            Dim myDataReader As OdbcDataReader

            Dim myCommand As OdbcCommand = New OdbcCommand("INSERT INTO objekt ( Lan, Kommun, Adress, Kategori, Boyta, Rum, Avgift, Pris, Bild, Beskrivning, Storbild1, Storbild2, Storbild3, Storbild4, Storbild5, Storbild6 ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", myConnection)
            'Ställ in parametrarna till den lagrade proceduren
            Dim objParam As OdbcParameter

            objParam = myCommand.Parameters.Add("Lan", OdbcType.VarChar)
            objParam.Value = tbLan.Value

            objParam = myCommand.Parameters.Add("Kommun", OdbcType.VarChar)
            objParam.Value = tbKommun.Value

            objParam = myCommand.Parameters.Add("Adress", OdbcType.VarChar)
            objParam.Value = tbAdress.Value

            objParam = myCommand.Parameters.Add("Kategori", OdbcType.VarChar)
            objParam.Value = tbKategori.Value

            objParam = myCommand.Parameters.Add("Boyta", CInt(tbBoyta.Value))
            'objParam.Value = tbBoyta.Value

            objParam = myCommand.Parameters.Add("Rum", CInt(tbRum.Value))
            'objParam.Value = tbRum.Value

            objParam = myCommand.Parameters.Add("Avgift", CInt(tbAvgift.Value))
            'objParam.Value = tbAvgift.Value

            objParam = myCommand.Parameters.Add("Pris", OdbcType.VarChar)
            'objParam.Value = tbPris.Value

            objParam = myCommand.Parameters.Add("Bild", strFileNameOnly1)
            'objParam.Value = strFileNameOnly1

            objParam = myCommand.Parameters.Add("Beskrivning", OdbcType.VarChar)
            objParam.Value = taBeskrivning.Value

            objParam = myCommand.Parameters.Add("Storbild1", OdbcType.VarChar)
            objParam.Value = strFileNameOnly1

            objParam = myCommand.Parameters.Add("Storbild2", OdbcType.VarChar)
            objParam.Value = strFileNameOnly2

            objParam = myCommand.Parameters.Add("Storbild3", OdbcType.VarChar)
            objParam.Value = strFileNameOnly3

            objParam = myCommand.Parameters.Add("Storbild4", OdbcType.VarChar)
            objParam.Value = strFileNameOnly4

            objParam = myCommand.Parameters.Add("Storbild5", OdbcType.VarChar)
            objParam.Value = strFileNameOnly5

            objParam = myCommand.Parameters.Add("Storbild6", OdbcType.VarChar)
            objParam.Value = strFileNameOnly6


            Catch ex As OdbcException
                lblMessage.Text = ex.Message
            End Try

            Dim myConnection2 As OdbcConnection = New OdbcConnection(ConfigurationSettings.AppSettings("ConnectionString"))

            Dim strTextFastig As String = tbFastighetsbeteckning.Value
            'erstter Retur-slag med <br> tag
            strTextFastig = Replace(strTextFastig, vbCrLf, "<br />")

            Dim strTextBesk As String = taBeskrivning.Value
            strTextBesk = Replace(strTextBesk, vbCrLf, "<br />")

            Dim strTextPlanl As String = taPlanlosning.Value
            strTextPlanl = Replace(strTextPlanl, vbCrLf, "<br />")

            Dim strTextBygg As String = taByggnadssatt.Value
            strTextBygg = Replace(strTextBygg, vbCrLf, "<br />")

            Dim strTextPlanb As String = taPlanbestammelser.Value
            strTextPlanb = Replace(strTextPlanb, vbCrLf, "<br />")

            Dim strTextTomt As String = taTomtbeskrivning.Value
            strTextTomt = Replace(strTextTomt, vbCrLf, "<br />")

            Dim strTextGarage As String = taGarage.Value
            strTextGarage = Replace(strTextGarage, vbCrLf, "<br />")

            Dim strTextEkonomi As String = taEkonomi.Value
            strTextEkonomi = Replace(strTextEkonomi, vbCrLf, "<br />")

            Dim strTextOvrigt As String = taOvrigt.Value
            strTextOvrigt = Replace(strTextOvrigt, vbCrLf, "<br />")

            Dim myDataReader2 As OdbcDataReader

            Dim myCommand2 As OdbcCommand = New OdbcCommand("INSERT INTO detaljer ( Fastighetsbeteckning, Beskrivning, Planlosning, Byggnadssatt, Planbestammelser, Tomtbeskrivning, Garage, Ekonomi, Ovrit ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", myConnection2)
            'Ställ in parametrarna till den lagrade proceduren
            Dim objParam2 As OdbcParameter

            objParam2 = myCommand2.Parameters.Add("Fastighetsbeteckning", OdbcType.VarChar)
            objParam2.Value = strTextFastig

            objParam2 = myCommand2.Parameters.Add("Beskrivning", OdbcType.VarChar)
            objParam2.Value = strTextBesk

            objParam2 = myCommand2.Parameters.Add("Planlosning", OdbcType.VarChar)
            objParam2.Value = strTextPlanl

            objParam2 = myCommand2.Parameters.Add("Byggnadssatt", OdbcType.VarChar)
            objParam2.Value = strTextBygg

            objParam2 = myCommand2.Parameters.Add("Planbestammelser", OdbcType.VarChar)
            objParam2.Value = strTextPlanb

            objParam2 = myCommand2.Parameters.Add("Tomtbeskrivning", OdbcType.VarChar)
            objParam2.Value = strTextTomt

            objParam2 = myCommand2.Parameters.Add("Garage", OdbcType.VarChar)
            objParam2.Value = strTextGarage

            objParam2 = myCommand2.Parameters.Add("Ekonomi", OdbcType.VarChar)
            objParam2.Value = strTextEkonomi

            objParam2 = myCommand2.Parameters.Add("Ovrigt", OdbcType.VarChar)
            objParam2.Value = strTextOvrigt

            'objParam = myCommand.Parameters.Add("@Bild1", odbcType.VarChar)
            'objParam.Value = taBild1.value

            Catch ex As OdbcException
                lblMessage.Text = ex.Message
            End Try

            lblMessage.Text = "Bilderna och informationen har sparats i databasen."
            lblMessage.Text = "problem med att överföra informationen till databasen"
        End If

    End Sub

End Class
Question by:viktor999
  • 5
  • 4

Expert Comment

ID: 11820543
Are you right clicking on the  "bilder" folder?  That's the folder that needs the permissions set.  You should be able to click "Properties", then the "Security Tab", and add the ASPNET user...

Author Comment

ID: 11829947
The problem is when I right clickon the  "bilder" folder and choose  "Properties", I can not find any "Security Tab" to add the ASPNET user! I don't know why and how to solve the problem. Is there any other way?Thanks

Expert Comment

ID: 11830247
What tabs do you see?  What OS are you running?
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.


Author Comment

ID: 11879548
The tabs that I see are something like (General- Give away- Webb sharing- Adapt)
I'm running Windows XPprofessionals.

Expert Comment

ID: 11881214
Are you navigating through explorer to the bilder folder?  Or through IIS?

Author Comment

ID: 11900752
I'm navigating through explorer to the "bilder" folder.
Should I do it through IIS? In this case what should I do exactly?Thanks

Expert Comment

ID: 11902502
I've never seen a "Give Away" or "Adapt" tab.  Not sure what's going on there....

The tabs you should see are:

General, Sharing, Security, Customize.

I'm using XP Pro as well....

Author Comment

ID: 11940146
Sorry about the wrong translation from swedish to english.
The tabs that I see are:
General, Sharing, Security, Customize.
Is there anything I can do to solve the problem

Accepted Solution

claygarrett earned 50 total points
ID: 11941964
Click on the security tab, and make sure the ASPNET user has full write permission to the bilder folder....

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on could not pull conte…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question