[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 312
  • Last Modified:

What's causing this error?

Apparently for the last several days, no emails have been sent due in part (apparently) to the following error:

Server Error in '/mars2' Application.


--------------------------------------------------------------------------------

Access to the path 'C:\www\mars2\Credit Card Authorization Form.doc' 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:\www\mars2\Credit Card Authorization Form.doc' 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 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 479:                if (!strFileName.Equals(""))

Line 480:                {

Line 481:                    FileUpload1.PostedFile.SaveAs(Server.MapPath(strFileName));

Line 482:

Line 483:                    MailAttachment attach = new MailAttachment(Server.MapPath(strFileName));
 


Source File: c:\www\mars2\EmailSendInvoice.aspx.cs    Line: 481

Stack Trace:

 

[UnauthorizedAccessException: Access to the path 'C:\www\mars2\Credit Card Authorization Form.doc' is denied.]

   System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +651

   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) +1038

   System.IO.FileStream..ctor(String path, FileMode mode) +64

   System.Web.HttpPostedFile.SaveAs(String filename) +87

   EmailSendInvoice.sendEmail(String id_orderheader, String session_id, Int32 type) in c:\www\mars2\EmailSendInvoice.aspx.cs:481

   EmailSendInvoice.btnEmail_Click(Object sender, EventArgs e) in c:\www\mars2\EmailSendInvoice.aspx.cs:603

   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105

   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107

   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7

   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11

   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33

   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint
 
I am so new to ASP.NET that I'm barely beyond the table of contents in "ASP. NET for Dummies." I know that this app is running off a SQL server and a lot of the functionality is in C#.

Any counsel would be most appreciated.
0
brucegust
Asked:
brucegust
3 Solutions
 
David H.H.LeeCommented:
Hi brucegust,
This is permission settings issue. You need to grant the permission to the uploaded folder as suggested in the detailed errors:
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.

Refer impersonate setting:
http://msdn.microsoft.com/en-us/library/aa292118(VS.71).aspx

Grant Permissions:
=================
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.

0
 
brucegustAuthor Commented:
Thanks x_com! I'll be dispatching your counsel first thing tomorrow morning when I head out to the site and try to impress them with my resources. I'll keep you posted...

Thanks...
0
 
Anurag ThakurCommented:
The exception log states whats actually wrong and how the exception can be removed

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 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.
0
 
GiftsonDJohnCommented:
Add Network and Network Services access to the folder. But it is not recommended. You can use the folder outside the web root and grant permission to update the file over there.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now