About SharePoint 2019 on premise custom Application Page

Will 616 Reputation points
2020-10-06T05:34:17.833+00:00

Hi there,

Today I ran into a problem is to deploy a custom application page in the SharePoint Farm (One is Application Server, another is WFE). When we access the custom application page, we got the following error: File not found. I am sure the *.aspx lives in the _layouts hive so the whole URL will be https://xxx.xxx.xxx/_layouts/15/somefolder/x.aspx. the code was installed in other SharePoint Farms are Standalone and work well. Finally, when we access the application page, I found out something wrong (401 Unauthorized) by IE [F12]

Does anyone have any idea on this problems?? Thanks

source code:

SPSecurity.RunWithElevatedPrivileges(delegate ()
            {
                SPFarm sPFarm = SPFarm.Local;

                foreach (SPService sPService in sPFarm.Services)
                {
                    if (sPService is SPWebService)
                    {
                        SPWebService sPWebService = (SPWebService)sPService;

                        foreach (SPWebApplication sPWebApplication in sPWebService.WebApplications)
                        {
                            foreach (SPSite sPSite in sPWebApplication.Sites)
                            {
                                Response.Write(sPSite.RootWeb.Title + "</br>");
                            }
                        }
                    }
                }
            });
Microsoft 365 and Office | SharePoint Server | For business
Microsoft 365 and Office | SharePoint Server | Development
0 comments No comments
{count} votes

Accepted answer
  1. Will 616 Reputation points
    2020-10-13T12:51:38.74+00:00

    Hi Jerry,

    I have sorted it out. the main cause is some orphan sites in DB. so when I extract all sites the error message comes up. I modified my source code and the error has gone.

    Thanks


3 additional answers

Sort by: Most helpful
  1. ZhengyuGuo 10,586 Reputation points Moderator
    2020-10-07T08:29:00.177+00:00

    @Will ,

    For "File not found", I suggest you could double check if the application page is hosted in /layouts folder like below:

    30672-snipaste-2020-10-07-16-27-25.png

    For 401 Unauthentication, did this happen for the whole application page or just the code snippet ? And what's the detailed request occured the 401 error ?


  2. sadomovalex 3,636 Reputation points
    2020-10-09T15:40:50.247+00:00

    for testing the path of custom application layout page you may also copy regular text file (test.txt - with some test text inside so it won't be empty) to the same folder c:\program files\common files\microsoft shared\Web Server Extensions\15\Template\Layouts\somefolder and then request it by url: https://xxx.xxx.xxx/_layouts/15/somefolder/text.txt. In this case ASP.Net pipeline won't be used and text file should be returned as is. If it won't be returned then most probably there is some problem in used url.

    If it will be returned - then path is valid. In this case ensure that assembly with codebehind for your page is installed to the GAC on WFE. If it is installed - try to temporary comment out all codebehind in your page and re-install assembly to the GAC (in order to test if codebehind causes File not found error).


  3. ZhengyuGuo 10,586 Reputation points Moderator
    2020-10-22T02:16:52.26+00:00

    Hi @Will ,

    Please remember to accept your own post above as answer if the problem is resolved so that it could help others in the forum.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.