Reputation: 439
Question: How to upload a file using <identity impersonate="true" />
and <authentication mode="Forms" />
Problem: I am using the following code snippet to upload files ...it works just fine when I use <identity impersonate="true" />
and <authentication mode="Windows" />
but as soon as I change <authentication mode="Windows" />
to <authentication mode="Forms" />
I get an access denied error.. How do I fix this problem?
I need to use <authentication mode="Forms" />
for my registration and login system to work. Hope you guys got my point.
If fuProfilePicture.HasFile Then
fuProfilePicture.SaveAs(System.IO.Path.Combine(Server.MapPath("ProfilePictures"), _userName & System.IO.Path.GetExtension(fuProfilePicture.FileName)))
Else
Response.Write("Select An Image")
End If
_profilePic = "ProfilePictures" & "/" & _userName & System.IO.Path.GetExtension(fuProfilePicture.FileName)
Upvotes: 0
Views: 193
Reputation: 44931
If you have specified a username in the web.config identity element, then this user needs to have write permissions to the directory you are trying to store files to.
Otherwise, the user for the application pool that your web site resides in needs to have write access to the target directory. Note that newer versions of IIS use an account of ApplicationPoolIdentity by default which I do not believe you can use to secure directories. If this is the case, you will need to change the application pool identity to at least Local Service, then secure the directory for this user.
If the directory you are trying to write to is a network share, you will need to ensure that you use a domain account either as the impersonated user or as the application pool identity.
Upvotes: 2