server error after deploying mvc app to aws

I have an asp.net MVC application which allows a user to upload PDFs onto the system (the PDF files get saved into a folder called Surveys). The PDFs then get sent onto the Azure Read API and the data returned is stored in a .text file on the system (so I can later enter some of the data into a database).

This works fine when I test locally using IIS Express; I can upload a PDF and a .text file is made with the returned text. The problem is when I deploy the web app (to aws elastic beanstalk in this case), I get a server error when I upload a PDF:

Server Error in ‘/BookingSystem_deploy’ Application.
Could not find a part of the path ‘C:inetpubwwwrootSurveysaaf6d80a-230f-4583-b57a-bf44ef49b903.pdf’.

My controller:

[HttpPost]
        public async Task<ActionResult> Upload(HttpPostedFileBase file)
        {
            string filename = Guid.NewGuid() + Path.GetExtension(file.FileName);
            string filepath = @"C:Users35385sourcereposBookingSystemBookingSystemSurveys" + filename;
            file.SaveAs(Path.Combine(Server.MapPath("/Surveys"), filename));
            await AzureVisionAPI.ExtractToTextFile(filepath);


            return View();
        }

I am guessing that the ‘string filepath’ needs to be changed in some way to support the directory change after deployment? Can anybody tell me what I need to do in this regard? Or if the error is something totally different that I am missing

edit: I have made some changes after doing some more research about my problem

changes to controller:

[HttpPost]
        public async Task<ActionResult> Upload(HttpPostedFileBase file)
        {
            string filename = Guid.NewGuid() + Path.GetExtension(file.FileName);
            string filepath = Server.MapPath(Path.Combine("~/Surveys/", filename));
            file.SaveAs(Server.MapPath(Path.Combine("~/Surveys/", filename)));
            await AzureVisionAPI.ExtractToTextFile(filepath);


            return View();
        }

Now I am receiving a different server error(although this one sounds like the path is now correct even though permission is denied):

Server Error in ‘/BookingSystem_deploy’ Application.
Access to the path ‘C:inetpubwwwrootBookingSystem_deploySurveys70c1528a-49ce-4ec2-814e-df83b150224e.pdf’ is denied.

Can anyone see what I am doing wrong?

1 Answer

1)Make sure enabled anonymous authentication in iis for your site.

2)your application pool identity is set as shown below:

enter image description here

set iis_iusrs, iusr permission to the site folder.

if application pool identity with not work then try to set the local system or network service.

to assign permission to the folder:

Right Click site Folder

Go to Security Tab

Click on Edit

Click on Add

Click on Advance

Find Now

Give Permission to IIS_IUSRS (Full Control)

Click On OK

Click On OK

Click On Full Control to allow

Click On OK

Again Run the Application

after assigning permission refresh site in iis.

Archive from: https://stackoverflow.com/questions/59012252/server-error-after-deploying-mvc-app-to-aws

Share

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *