Grant ASP.NET MVC 3 website write access to ~/Content/uploads folder - asp.net

I have an ASP.NET MVC 3 website that runs on the company intranet to which I want to add a page that can upload files to the server.
I am running the site on Windows Server 2012 with IIS 8.
IIS Config:
Application pool attributes:
.Net Framework v4.0
Managed Pipeline Mode: Integrated
Identity: LocalSystem
Under the site node, authentication is set as:
Windows Authentication: Enabled (Users must use their corporate Windows Accounts to log in)
All other Authentication including Anonymous Authentication set to Disabled.
Windows Permissions:
In the Content directory, I have granted all access permissions to the System, Admin and my User's account.
MVC Code:
The MVC Controller method that handles the file upload contains the following code:
[HttpPost]
public ActionResult Upload(HttpPostedFileBase file)
{
if (file != null && file.ContentLength > 0)
{
var fileName = Path.GetFileName(file.FileName);
DateTime timestamp = DateTime.Today;
var path = Path.Combine(Server.MapPath("~/Content/uploads"), fileName);
if( !Directory.Exists(path))
Directory.CreateDirectory(path);
file.SaveAs(path);
}
return RedirectToAction("Index");
}
When I try to upload a file using the above controller I get the following error:
Server Error in '/' Application.
Access to the path 'C:\Sites\ClosedBeta\Content\uploads\test.csv' 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:\Sites\ClosedBeta\Content\uploads\test.csv' 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 and IIS 7, and the configured application pool identity on IIS 7.5) 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 access to a file, right-click the file in File 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 34: if( !Directory.Exists(path))
Line 35: Directory.CreateDirectory(path);
Line 36: file.SaveAs(path);
Line 37: }
Line 38:
Source File: C:\Users\****\Documents\Visual Studio 2010\Projects\Solution\Project\Controllers\UploadTestController.cs Line: 36
Stack Trace:
[UnauthorizedAccessException: Access to the path 'C:\Sites\ClosedBeta\Content\uploads\test.csv' is denied.]
System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +10760710
System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) +1352
System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy) +60
System.IO.FileStream..ctor(String path, FileMode mode) +55
System.Web.HttpPostedFile.SaveAs(String filename) +94
System.Web.HttpPostedFileWrapper.SaveAs(String filename) +9
Project.Controllers.UploadTestController.Upload(HttpPostedFileBase file) in C:\Users\****\Documents\Visual Studio 2010\Projects\Solution\Project\Controllers\UploadTestController.cs:36
lambda_method(Closure , ControllerBase , Object[] ) +180
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +214
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +55
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +253
System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +21
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +191
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +324
System.Web.Mvc.Controller.ExecuteCore() +106
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +91
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +34
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +19
System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +10
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +48
System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9629708
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
Any adivce would be apreciated

I think that the problem was simply that I needed to wait a bit for the permissions to take effect.
After Comming back to the same code the next day, it worked perfectly.

simply go though iis check is IISUSER and IUSR_ has permission to read and write
Generally plesk panel and cpanel add default permission to read list and write but in some cases something goes wrong and u need to setup the right permission.
So you have 2 way to achive your goal:
If you have access to iss do it by youself
or
Ask to your hosting company to setup write and read permission to this particular folder.

Related

Parsing property in ASP version 4 causes FormatException

I have this code fragment
public Version BuildVersion =Version.Parse(System.Web.Configuration.WebConfigurationManager.AppSettings["BuildVersion"].ToString());
which reads following appSetting entry
<appSettings>
<add key="BuildVersion" value="4.7.2.2" />
</appSettings>
This throws exception
[FormatException: Input string was not in a correct format.]
System.VersionResult.SetFailure(ParseFailureKind failure, String argument) +10852983
System.Version.TryParseComponent(String component, String componentName, VersionResult& result, Int32& parsedComponent) +105
System.Version.TryParseVersion(String version, VersionResult& result) +135
System.Version.Parse(String input) +68
QuickPick.Main..ctor() in D:\IWROX-DEV\Expresslane\IWorx-Trunk-PromoFrontEnd\ExpressLane.Web\Main.Master.cs:52
ASP.main_master..ctor() in c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\e43b3107\2f748eb6\App_Web_main.master.cdcab7d2.uaxqveln.0.cs:0
__ASP.FastObjectFactory_app_web_main_master_cdcab7d2_uaxqveln.Create_ASP_main_master() in c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\e43b3107\2f748eb6\App_Web_main.master.cdcab7d2.uaxqveln.1.cs:0
System.Web.Compilation.BuildResultCompiledType.CreateInstance() +30
System.Web.UI.MasterPage.CreateMaster(TemplateControl owner, HttpContext context, VirtualPath masterPageFile, IDictionary contentTemplateCollection) +782
System.Web.UI.Page.get_Master() +54
System.Web.UI.Page.ApplyMasterPage() +14
System.Web.UI.Page.PerformPreInit() +45
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +335
once deployed to the server, However it runs fine on VS2010 web host (ASP NET Development Server).
Most likely the correct config file is not deployed to your host.

.Net Framework Data Provider May Not Be Installed?

I have an ASP.NET website created in VS 2010 which is using the MVC3 (Razor) and Entity Framework and MSSQL database. The project runs fine on my machine, however when I publish and upload to my host I get the error:
Unable to find the requested .Net Framework Data Provider. It may not be installed.
Now I believe that I have added all required DLLs to my /bin folder. This is my connection string in the web.config file:
Connection String
<add name="WhimsicalFurnishingEntities"
connectionString="metadata=res://*/App_Code.WhimsicalFurnishingModel.csdl|res://*/App_Code.WhimsicalFurnishingModel.ssdl|res://*/App_Code.WhimsicalFurnishingModel.msl;
provider=System.Data.SqlClient;
provider connection string="
data source=localhost\sqlexpress;
Initial Catalog=DBNAME;
integrated security=True;
User ID=DBUSER;
Password=DBPASSWORD;
user instance=True;
multipleactiveresultsets=True;
App=EntityFramework""
providerName="System.Data.EntityClient" />
I have read that you might need to add another connection string just for the database SQL Client and I have tried:
What I Have Tried
<add name="WhimsicalFurnishingMembership"
connectionString="data source=localhost\sqlexpress;Initial Catalog=DBNAME;Integrated Security=false;User ID=DBUSER;Password=DBPASSWORD;"
providerName="System.Data.SqlClient"/>
However the same error persists. This is the exact error that I am getting from Stack Trace:
[ArgumentException: Unable to find the requested .Net Framework Data Provider. It may not be installed.
]
System.Data.Common.DbProviderFactories.GetFactory(String providerInvariantName) +1434271
WebMatrix.Data.DbProviderFactoryWrapper.CreateConnection(String connectionString) +64
WebMatrix.Data.<>c__DisplayClass15.<OpenConnectionStringInternal>b__14() +16
WebMatrix.Data.Database.get_Connection() +19
WebMatrix.Data.Database.EnsureConnectionOpen() +12
WebMatrix.Data.<QueryInternal>d__0.MoveNext() +71
System.Linq.Enumerable.FirstOrDefault(IEnumerable`1 source) +4231764
WebMatrix.Data.Database.QuerySingle(String commandText, Object[] args) +103
WebMatrix.WebData.SimpleMembershipProvider.CheckTableExists(Database db, String tableName) +59
WebMatrix.WebData.SimpleMembershipProvider.CreateTablesIfNeeded() +55
WebMatrix.WebData.WebSecurity.InitializeMembershipProvider(SimpleMembershipProvider sMembership, DatabaseConnectionInfo connect, String userTableName, String userIdColumn, String userNameColumn, Boolean createTables) +73
WebMatrix.WebData.WebSecurity.InitializeProviders(DatabaseConnectionInfo connect, String userTableName, String userIdColumn, String userNameColumn, Boolean autoCreateTables) +51
WebMatrix.WebData.WebSecurity.InitializeDatabaseConnection(String connectionStringName, String userTableName, String userIdColumn, String userNameColumn, Boolean autoCreateTables) +51
ASP._Page__AppStart_cshtml.Execute() in ******\wwwroot\_AppStart.cshtml:3
System.Web.WebPages.ApplicationStartPage.<ExecuteInternal>b__3() +65
System.Web.WebPages.ApplicationStartPage.<GetSafeExecuteStartPageThunk>b__a(Action action) +7
System.Web.WebPages.ApplicationStartPage.ExecuteInternal() +78
System.Web.WebPages.ApplicationStartPage.ExecuteStartPageInternal(HttpApplication application, Action`1 monitorFile, Func`2 fileExists, Func`2 createInstance, IEnumerable`1 supportedExtensions) +202
System.Web.WebPages.ApplicationStartPage.ExecuteStartPage(HttpApplication application, Action`1 monitorFile, Func`2 fileExists, Func`2 createInstance, IEnumerable`1 supportedExtensions) +41
[HttpException (0x80004005): Exception of type 'System.Web.HttpException' was thrown.]
System.Web.WebPages.ApplicationStartPage.ExecuteStartPage(HttpApplication application, Action`1 monitorFile, Func`2 fileExists, Func`2 createInstance, IEnumerable`1 supportedExtensions) +88
System.Web.WebPages.ApplicationStartPage.ExecuteStartPage(HttpApplication application) +287
System.Web.WebPages.WebPageHttpModule.StartApplication(HttpApplication application, Action`1 executeStartPage, EventHandler applicationStart) +113
System.Web.WebPages.WebPageHttpModule.StartApplication(HttpApplication application) +71
System.Web.WebPages.WebPageHttpModule.Init(HttpApplication application) +217
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +517
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +194
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +339
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +253
[HttpException (0x80004005): Exception of type 'System.Web.HttpException' was thrown.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9090876
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +97
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +256
Is there another way I can try to debug this? Am I missing anything that must be included in my web.config or _AppStart.cshtml file?
Thank You

System.DirectoryServices.DirectoryServicesCOMException

I keep getting the following error when trying to run an application in the production environment with "anonymous" authentication and hardcoded username.
When I turn on basic authentication, which then prompts for username/password everything works like a charm. but I need to get the hardcoded version to work as well. Can't figure out whats going on.
Everything works perfectly on another server.
Exception Details: System.DirectoryServices.DirectoryServicesCOMException: An operations
error occurred.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of
the exception can be identified using the exception stack trace below.
Stack Trace:
[DirectoryServicesCOMException (0x80072020): An operations error occurred.]
System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) +781
System.DirectoryServices.DirectoryEntry.Bind() +44
System.DirectoryServices.DirectoryEntry.get_SchemaEntry() +49
System.DirectoryServices.AccountManagement.ADStoreCtx.IsContainer(DirectoryEntry
de) +62
System.DirectoryServices.AccountManagement.ADStoreCtx..ctor(DirectoryEntry
ctxBase, Boolean ownCtxBase, String username, String password,
ContextOptions options) +123
System.DirectoryServices.AccountManagement.PrincipalContext.CreateContextFromDirectoryEntry(DirectoryEntry
entry) +234
System.DirectoryServices.AccountManagement.PrincipalContext.DoLDAPDirectoryInit()
+497
[PrincipalOperationException: An operations error occurred.]
System.DirectoryServices.AccountManagement.PrincipalContext.DoLDAPDirectoryInit()
+534256
System.DirectoryServices.AccountManagement.PrincipalContext.DoDomainInit()
+61
System.DirectoryServices.AccountManagement.PrincipalContext.Initialize()
+141
System.DirectoryServices.AccountManagement.PrincipalContext.get_QueryCtx()
+42
System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithTypeHelper(PrincipalContext
context, Type principalType, Nullable`1 identityType, String
identityValue, DateTime refDate) +27
System.DirectoryServices.AccountManagement.GroupPrincipal.FindByIdentity(PrincipalContext
context, String identityValue) +95
SERT_BO.ADHelper.UserBelongsToGrp(String adGroup, String sAMAccountName, String& emailAddr, String& fullName) in
D:\SERT\BusinessObjects\SERT_BO\ADHelper.cs:199
SERT_BO.UserSession.GetUserSession(String userName) in D:\SERT\BusinessObjects\SERT_BO\UserSession.cs:44
SERT.SetUserSession.Page_Load(Object sender, EventArgs e) in D:\SERT\SERT\SERT\SetUserSession.aspx.cs:23
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +25
System.Web.UI.Control.LoadRecursive() +71
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+3064
One thing to check is that the AppPool in which the ASP.NET app is running has the right privileges. As a quick test you can set the identity of the AppPool to Local System and see if this solves the issue. If the problem is here, then you can set the application pool identity to a (domain?) user that has enough privileges on this server.
looks like the issue was that the server was looking at the wrong AD controller. it had to be written out COMPLETELY.

ASP MVC2 deploying to IIS 7 with error

after I deployed the application to IIS7 server, it seems fine at the beginning and can display the login page. But after the user inputted the username and password, I have to authenticate the user with the DB connection. At this time, it display error (attached). I guess the error is caused by the reflection during the EntityFramwork load the DB data.
My server has been installed .net framework 3.5 sp1 already.
On the other hand, I have tried another server. If a server has been installed VS2008 and MVC2 package for VS2008, that server can run the application properly in IIS7.
My aim is to run the application on a IIS7 server with .net framework 3.5 only.
Please help me solve this problem.
The error datails:
Server Error in '/FDDV_demo' Application.
--------------------------------------------------------------------------------
Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
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.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.]
System.Reflection.Module._GetTypesInternal(StackCrawlMark& stackMark) +0
System.Reflection.Assembly.GetTypes() +111
System.Data.Metadata.Edm.AssemblyCacheEntry.LoadTypesFromAssembly(LoadingContext context) +28
System.Data.Metadata.Edm.AssemblyCacheEntry.InternalLoadAssemblyFromCache(LoadingContext context) +290
System.Data.Metadata.Edm.AssemblyCacheEntry.LoadAssemblyFromCache(Assembly assembly, Boolean loadReferencedAssemblies, Dictionary`2 knownAssemblies, Dictionary`2& typesInLoading, List`1& errors) +137
System.Data.Metadata.Edm.ObjectItemCollection.LoadAssemblyFromCache(ObjectItemCollection objectItemCollection, Assembly assembly, Boolean loadReferencedAssemblies) +284
System.Data.Metadata.Edm.ObjectItemCollection.LoadAssemblyForType(Type type) +33
System.Data.Metadata.Edm.MetadataWorkspace.LoadAssemblyForType(Type type, Assembly callingAssembly) +80
System.Data.Objects.ObjectContext.CreateQuery(String queryString, ObjectParameter[] parameters) +106
FDDV.Models.DBEntities.get_user_master() +113
FDDV.Controllers.HomeController.validateUser(String userid, String password) +254
FDDV.Controllers.HomeController.LogOn(LogOnModel model, String returnUrl) +134
lambda_method(ExecutionScope , ControllerBase , Object[] ) +136
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +17
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +178
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +24
System.Web.Mvc.<>c__DisplayClassd.<InvokeActionMethodWithFilters>b__a() +53
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +258
System.Web.Mvc.<>c__DisplayClassf.<InvokeActionMethodWithFilters>b__c() +20
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +193
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +316
System.Web.Mvc.Controller.ExecuteCore() +104
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +36
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +7
System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__4() +34
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21
System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +53
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +43
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +7
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8682542
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.4952; ASP.NET Version:2.0.50727.4955
I finally solved this problem. The main cause is the project missed some assembly references. I add the following code to the login function to find out the reflection type load exception. Once again, thanks everyone 's helpful
try{
//Do your work
}
catch (Exception ex)
{
ReflectionTypeLoadException exception = ex as ReflectionTypeLoadException;
if (exception == null)
System.IO.File.AppendAllText("C:\\TestLog.txt", "Not a ReflectionTypeLoadException ex.");
else
{
foreach (Exception loaderException in exception.LoaderExceptions)
{
System.IO.File.AppendAllText("C:\\TestLog.txt", loaderException.Message);
System.IO.File.AppendAllText("C:\\TestLog.txt", loaderException.StackTrace);
}
}
return true;
}
I faintly recall having a similar issue with MVC 3 when I upgraded a project from MVC 2 and had some version issues in my web.config.
Try enabling fusion assembly log binding and see if you can find maybe what the load is failing on.
http://www.hanselman.com/blog/BackToBasicsUsingFusionLogViewerToDebugObscureLoaderErrors.aspx
I found a script a while back that allowed me to work with fusion log better in IIS (I was having problems where it didn't run in IIS).

upload pictures

Hello everyone i have a problem with my website. When i upload pics using my local host, it works fine but when i try to upload the pics from the internet, i have the following error message:
Server Error in '/please-god' Application.
Access to the path 'D:\Hosting\4423045\html\please-god\UploadedImages\3.jpg' 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 'D:\Hosting\4423045\html\please-god\UploadedImages\3.jpg' 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 , the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.
To grant ASP.NET 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 21: If imageUpload.HasFile Then
Line 22: Dim baseDirectory As String = Server.MapPath("~/UploadedImages/")
Line 23: imageUpload.SaveAs(baseDirectory & pictureIDJustAdded & ".jpg")
Line 24: End If
Line 25: End If
Source File: D:\Hosting\4423045\html\please-god\PhotoAdmin\Default.aspx.vb Line: 23
Stack Trace:
[UnauthorizedAccessException: Access to the path 'D:\Hosting\4423045\html\please-god\UploadedImages\3.jpg' is denied.]
System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +7715167
System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) +1162
System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy) +61
System.IO.FileStream..ctor(String path, FileMode mode) +55
System.Web.HttpPostedFile.SaveAs(String filename) +99
System.Web.UI.WebControls.FileUpload.SaveAs(String filename) +23
PhotoAdmin_Default.dvPictureInsert_ItemInserted(Object sender, DetailsViewInsertedEventArgs e) in D:\Hosting\4423045\html\please-god\PhotoAdmin\Default.aspx.vb:23
System.Web.UI.WebControls.DetailsView.OnItemInserted(DetailsViewInsertedEventArgs e) +108
System.Web.UI.WebControls.DetailsView.HandleInsertCallback(Int32 affectedRows, Exception ex) +69
System.Web.UI.DataSourceView.Insert(IDictionary values, DataSourceViewOperationCallback callback) +134
System.Web.UI.WebControls.DetailsView.HandleInsert(String commandArg, Boolean causesValidation) +274
System.Web.UI.WebControls.DetailsView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +676
System.Web.UI.WebControls.DetailsView.OnBubbleEvent(Object source, EventArgs e) +95
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
System.Web.UI.WebControls.DetailsViewRow.OnBubbleEvent(Object source, EventArgs e) +113
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +118
System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +135
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +175
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
You need to give permissions to the IIS user to that directory. The error message provides information on what to do, but there is more info below
More info here - http://www.webdeveloper.com/forum/showthread.php?t=131624
or
https://stackoverflow.com/search?q=Exception+Details%3A+System.UnauthorizedAccessException

Resources