3

I created an image uploading app for a client and they want to host it on its own IIS server. When I publish the app to the server I get the error

HTTP Error 500.30 - ASP.NET Core app failed to start

I have installed all the .NET v6 SDK, Runtime and hosting bundle that is needed to host the app.

After looking around on SO and google I was able to run the appNameHere.dll from the command prompt and it runs just fine without showing any errors. When I do that I can open it locally on the server and have the app show up. It's just when it's public facing I get the error.

I have narrowed it down to these few lines of code in the Program.cs file

app.UseStaticFiles();    
app.UseStaticFiles(new StaticFileOptions()
{
    FileProvider = new PhysicalFileProvider(Path.GetFullPath("\\\\12.34.56.789\\c$\\ABC\\FolderName\\ProjectName\\Images\\ItemImages\\")),    
    RequestPath = new PathString("/ItemImages")
 });

When I comment these out, the app shows up fine and works, but I can't get the files from the other site.

I can also set up a folder locally in the "C:\UnitImages" and everything works as well.

I created a shared connection to the main server to test the path as well and it works there too. So I'm a bit lost on where to go next.

Update

As stated in one of the links from @Code Maverick I have updated the Application Pool Identity to the user that has full access to the folders and I still get the Error that's stated above.

I came across this article and tried it but I'm getting an error 'NetworkConnection' is a namespace but is used like a type

repo for ref.

 var sourceCredentials = new NetworkCredential { Domain = "12.34.56.789", UserName = "Administrator", Password = "123456" };

using (new NetworkConnection("\\\\12.34.56.789\\c$\\ABC\\FolderName\\ProjectName\\Images\\UnitImages\\", sourceCredentials))
{
    // to serve static froms from \\network\shared location
    app.UseStaticFiles(new StaticFileOptions()
    {
        FileProvider = new PhysicalFileProvider(Path.GetFullPath("\\\\12.34.56.789\\c$\\ABC\\FolderName\\ProjectName\\Images\\UnitImages\\")),
        RequestPath = new PathString("/UnitImages")
    });
}
whisk
  • 713
  • 1
  • 10
  • 34
  • did you also provide access to the same user on folder as well? like same user on application pool identity should exist on folder security, if its a network drive then you must use AD user, – sairfan Feb 13 '23 at 17:01
  • Yes, when I go to the destination folder I have the same user/access there as well. If I'm reading this right I want to use the User Acct of the server that the app is currently on. – whisk Feb 13 '23 at 18:34
  • by network path i understand files you want to access are on some different computer not the one you have web site hosted on, in this case web app user does not have access to that shared folder because if a different computer, to ensure it you can temporarily assign access to shared folder as everyone/anonymous i believe then your web site will be able to access files on the folder, from there we can figure out how can to set proper user rights on the folder to make it accessible to web app. – sairfan Feb 13 '23 at 20:54
  • so I've logged in to both servers and set up share drives and pings both internal IP's. I think it has to do with the web app not being allowed to access the files because its not assigned user credentials. Does that make sense? – whisk Feb 13 '23 at 21:06
  • when you try to access file system through web app, only web app user's security policy will be applied – sairfan Feb 13 '23 at 21:08
  • I suggest you could try to use remote debug to debug the application which hosted at the IIS. More details about how to do it, you could refer to this [article](https://learn.microsoft.com/en-us/visualstudio/debugger/remote-debugging?view=vs-2022). – Brando Zhang Feb 16 '23 at 07:14
  • NetworkConnection is not a class in System.Net, and you don't have one defined in your project. If you followed the link in your article to the SO question here https://stackoverflow.com/questions/58624750/ that describes the NetworkConnection class you need to define for this to work. – Stephen Wrighton Feb 19 '23 at 16:56

1 Answers1

3

Based on this and this, you may need to provide IIS_IUSRS group the ability to write to the share.

You personally may be able to access the share, but your web application hosted within IIS needs the same access privilege. This does have security implications though.

Code Maverick
  • 326
  • 2
  • 6