As for this question, I found the mainly reason is ClientID and ClientSecret. I found sometimes I register a new ClientID and ClientSecret cannot work. So I changed some information format. as follows:
When I register the App, Redirect URI: I give it whole URL ( must include Port Number ) like this https://XXXXX.azurewebsites.net:443/Pages/SettingSecurity.aspx
before solving the issue, My redirect URI is “https://XXXXX.azurewebsites.net” … I don’t know whether or not this is the mainly problem to influence my code. But finally I sorted it out.
Other Problems are:
AppManifest: When I published the “App for SharePoint”, I didn’t change the Url (~remoteAppUrl ) to the Url of the Production with the port number explicit.
- Debugging: <StartPage>~remoteAppUrl/Pages/SettingSecurity.aspx?{StandardTokens}</StartPage>
Production: <!–<StartPage>https://XXXXX.azurewebsites.net:443/Pages/SettingSecurity.aspx?{StandardTokens}</StartPage>–> - if you wanna debug it, pay close attention to the following line: ClientId=”*” ( don’t need to add any ClientId, keep * ), on the contrary, if you wanna publish it into the Production, you need to change ” * ” to ID like ( ad95a175-b4bb-481e-b644-526b5f37ae02 )
<AppPrincipal>
<RemoteWebApplication ClientId=”*” />
</AppPrincipal>
Elements.XML: It’s the same with the AppManifest
- <UrlAction Url=”~remoteAppUrl/Pages/SettingSecurity.aspx?{StandardTokens}&SPListItemId={ItemId}&SPListId={ListId}&SPSource={Source}&SPListURLDir={ListUrlDir}&SPItemURL={ItemUrl}”/>
- <!–<UrlAction Url=”https://XXXXX.azurewebsites.net:443/Pages/SettingSecurity.aspx?{StandardTokens}&SPListItemId={ItemId}&SPListId={ListId}&SPSource={Source}&SPListURLDir={ListUrlDir}&SPItemURL={ItemUrl}”/>–>