0

using: VS-2017(as admin), sitecore-8.1.2 and SQL - 2012.

I created a ASP.Net web application - WebAPI to read content from my local sitecore instance.

In the "ValuesController.cs" I am using the below code.

// GET api/values
    public string Get()
    {
        var context = Sitecore.Configuration.Factory.GetDatabase("master");
        string itemPath = "/sitecore/content/Home";
        Sitecore.Data.Items.Item item = context.Items[itemPath,Sitecore.Globalization.Language.Predefined.English];
        return item.GetOuterXml(true);
    }

FYI - I copied all the app_config folder and added all .dll's into the project, from my local sitecore instance

Build-succeeded. When I try to run the project in IE/Chrome it's working fine, but if I trying to access this URL- http://localhost:1025/api/values I am getting the below error. SQL issue

with the stackTrace:

at System.Web.DataAccess.SqlConnectionHelper.CreateMdfFile(String fullFileName, String dataDir, String connectionString) at System.Web.DataAccess.SqlConnectionHelper.EnsureDBFile(String connectionString) at System.Web.DataAccess.SqlConnectionHelper.GetConnection(String connectionString, Boolean revertImpersonation) at System.Web.Security.SqlRoleProvider.IsUserInRole(String username, String roleName) at System.Web.Security.Roles.IsUserInRole(String username, String roleName) at Sitecore.Security.Accounts.RolesInRolesProvider.IsUserInRole(User user, Role targetRole, Boolean includeIndirectMemberships) at Sitecore.Security.Accounts.User.IsInRole(String roleName) at Sitecore.Security.Accounts.User.IsInRole(Role role) at Sitecore.Security.Accounts.Role.IsMember(Account account, Boolean includeRoleMembers, Boolean includeEveryoneMembers) at Sitecore.Security.AccessControl.AccessRule.RuleAppliesToAccount(Account account, Boolean includeRoleMembers, Boolean includeEveryoneMembers)
at Sitecore.Security.AccessControl.AccessRule.RuleApplies(Account account, AccessRight accessRight, PropagationType propagationType, Boolean includeRoleMembers, Boolean includeEveryoneMembers) at Sitecore.Security.AccessControl.AccessRule.IsMatch(Account account, AccessRight accessRight, PropagationType propagationType, AccessPermission permission, Boolean includeRoleMembers, Boolean includeEveryoneMembers) at Sitecore.Security.AccessControl.AccessRuleCollectionHelper.GetMatchingRule(Account account, AccessRight accessRight, PropagationType propagationType, AccessPermission permission, Boolean includeRoleMembers, Boolean includeEveryoneMembers) at Sitecore.Security.AccessControl.AccessRuleCollectionHelper.GetMatchingRule(Account account, AccessRight accessRight, PropagationType propagationType)
at Sitecore.Security.AccessControl.ItemAuthorizationHelper.GetItemAccess(Item item, Account account, AccessRight accessRight, PropagationType propagationType) at Sitecore.Buckets.Security.AuthenticationHelper.GetItemAccess(Item item, Account account, AccessRight accessRight, PropagationType propagationType) at Sitecore.Security.AccessControl.ItemAuthorizationHelper.GetAccess(Item item, Account account, AccessRight accessRight) at Sitecore.Security.AccessControl.SqlAuthorizationProvider.GetItemAccess(Item item, Account account, AccessRight accessRight) at Sitecore.Security.AccessControl.SqlAuthorizationProvider.GetAccessCore(ISecurable entity, Account account, AccessRight accessRight) at Sitecore.Security.AccessControl.AuthorizationProvider.GetAccess(ISecurable entity, Account account, AccessRight accessRight) at Sitecore.Security.AccessControl.AuthorizationManager.GetAccess(ISecurable entity, Account account, AccessRight accessRight) at Sitecore.Security.AccessControl.AuthorizationManager.IsAllowed(ISecurable entity, AccessRight right, Account account) at Sitecore.Security.AccessControl.ItemAccess.CanRead() at Sitecore.Data.Managers.ItemProvider.ApplySecurity(Item item, SecurityCheck securityCheck) at Sitecore.Data.Managers.ItemProvider.GetItem(ID itemId, Language language, Version version, Database database, SecurityCheck securityCheck) at Sitecore.Data.Managers.ItemProvider.GetItem(String itemPath, Language language, Version version, Database database, SecurityCheck securityCheck) at Sitecore.Data.Managers.PipelineBasedItemProvider.<>c__DisplayClass2f.b__2e() at Sitecore.Data.Managers.PipelineBasedItemProvider.ExecuteAndReturnResult[TArgs,TResult](String pipelineName, String pipelineDomain, Func 1 pipelineArgsCreator, Func 1 fallbackResult) at Sitecore.Data.Managers.PipelineBasedItemProvider.GetItem(String itemPath, Language language, Version version, Database database, SecurityCheck securityCheck) at Sitecore.Data.Managers.ItemManager.GetItem(String itemPath, Language language, Version version, Database database) at Sitecore.Data.ItemRecords.get_Item(String itemPath, Language language) at Sitecore.WebAPI.Controllers.ValuesController.Get() in C:\Users\sreddy1\Downloads\SitecoreSSCAndroid-master\Sitecore.WebAPI\Controllers\ValuesController.cs:line 20 at lambda_method(Closure , Object , Object[] ) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.b__9(Object instance, Object[] methodParameters) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)

Thanks in advance!

1 Answer 1

1

The best way to create REST api service in sitecore is using the ServiceAPI. Since you're using sitecore 8.1, you can create webapi services easily. Kindly follow below articles.

http://hookedon.digital/2015/12/03/leveraging-the-servicesapicontroller-part-1-implementing-a-sitecore-service-api-controller/

you can even customize the routes as follows. http://hookedon.digital/2016/05/08/sitecore-service-api-controller-and-custom-routes/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.