Tuesday, September 8, 2015

SharePoint Hosted App error: This page can't be displayed

I did not get an opportunity to work on App model in SharePoint 2013 but I wanted to crack. I decided to give it a try from simple (I thought its very simple) SharePoint hosted app.

What I did;
- Opened Visual Studio 2013
- Created new project with template "Apps for SharePoint"
- Decided to deploy it without changing any code but without hitting F5 key
- Packaged the app

Then, what to do ? !!!!! I was wondering how to deploy the .app package manually.
Answer: "App Catalog".

I created a App catalog for my web application because it was not created earlier.
To Create App catalog:
- Go to Central Admin (Farm admin login)
- Navigate to "Apps" from left hand side navigation
- Click "Manage App Catalog" under App Management
Manage App Catalog
- Create a new app catalog site. You must choose your web application. [App catalog is a separate site collection to hold apps.]
Create App catalog

- That's it !!!!!

I uploaded my SharePoint hosted app in newly created app catalog site. Then I went to my site and added the test app [Your app will be listed in your application on "Add an app" page].

After adding my test app, I clicked it. BOOM !!!!!
Error: This page can't be displayed

After research I found DNS is needed. I installed DNS on my DEV machine.
[We need to configure Forward lookup zones, CNAME after installing DNS. Refer: https://technet.microsoft.com/en-us/library/fp161236.aspx ]

I tested my app. Uuh ! Same error.
I gave up and decided to deploy the app from visual studio. I hit F5 and Blast ! Received different error in Visual studio saying it cannot install the app. Whaaaaaaat !

Then packaged and uploaded the app manually through app catalog.
Opened my app. Aaaaaah ! Now different error with correlation ID. I checked SharePoint logs and it was mentioned that "User agent not found......".
Does it need Secure Store Service ? !!!!! I don't know.
I checked my DEV machine and found that Secure Store Service was not created. I have created it and checked my test app. Brought the same error. :) "This page can't be displayed".

Thinking thinking thinking !!!!!

Somewhere I came across the word "hosts" file. I gave it a try.
[Before you proceed, you need to have app instance ID and app URL.]

To find App instance ID:
- Go to Site Contents
- Hover on your App and right click & copy the url
  (Looks like http://<your site>/_layouts/15/appredirect.aspx?instance_id={AAB6792E-0225-4CA0-9D68-BDD970E37ECB})
Instance ID; AAB6792E-0225-4CA0-9D68-BDD970E37ECB

To find App URL:
- Click on your app from your application. (It throws the error)
- Copy the URL from address bar
   (Looks like http://apps-91d6298c4b4348.<site name>/SharePointApp2/Pages/Default.aspx?SPHostUrl=.........)
URL: apps-91d6298c4b4348.<site name>

Edit Hosts file:
- Go to %systemroot%/system32/Drivers/etc
- Create an entry at last.
 
  127.0.0.1 apps-91d6298c4b4348.<site> # AAB6792E-0225-4CA0-9D68-BDD970E37ECB;http://<site>/
::1 apps-91d6298c4b4348.<site> # AAB6792E-0225-4CA0-9D68-BDD970E37ECB;http://<site>/

Ex:
Let's assume my web app is sharepoint and site collection is sharepoint:1425

127.0.0.1 apps-91d6298c4b4348.sharepoint # AAB6792E-0225-4CA0-9D68-BDD970E37ECB;http://sharepoint:1425/
::1 apps-91d6298c4b4348.sharepoint # AAB6792E-0225-4CA0-9D68-BDD970E37ECB;http://sharepoint:1425/

- Save the hosts file

Now opened my test app.
Hurray !!!!!!!!!!!!!

Success !

To consider:
1. App Catalog
2. Make sure the necessary service is running "App Management services and Subscription Settings".
3. DNS
4. Secure Store Service
5. Hosts file [We need to edit it since we are running the app in DEV where it has separate domain]

P.S: I'm lucky enough to get a plain DEV machine. ;)



0 comments:

Post a Comment