I have found the solution.
When I was creating the ContextToken
object in that I was passing the SPHostUrl
of the request but instead of that I passed SPAppWebUrl
So using that it get the token of the AppWebUrl and thus it created the list in my App not in SharePoint site.
Like bellow code:
var hostWeb = Page.Request["SPAppWebUrl"]; //This will get the URL of AppWeb not SharePoint site...
using (var clientContext = TokenHelper.GetClientContextWithContextToken(hostWeb, ContextToken, Request.Url.Authority))
{
//Code for creating list or manipulating them...
//This ClientContext is created for the AppWeb.
}
When I was searching the code for creating every time I was finding the hostWeb
object is created using SPHostUrl
Therefore I asked this question.
Thank you everyone for your help.