Reading sharepoint site through object model within ASP.NET website produces errors

564 Views Asked by At

Scneario : Webserver with ASP.NET site. Installed Sharepoint 2010 SQL Express edition on the same server. SQL resides on the same box.

The ASP.NET runs on appPool1 with identity "SiteUser". The Sharepoint site that was created by the wizard has created new app-pool and the app-pool is set with network identity as 'Networkservice account'

Within one of the pages (common.aspx.cs), I read the sharepoint site using the below code.

        SPSecurity.RunWithElevatedPrivileges(delegate()
        {
        using (SPSite site = new SPSite(cSPSite))
        {
                    ...
        }
        });

Here are the errors.

The Web application at http://x2009:190/ could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application.

I did google a bit and no success yet. I can't compile this as it is ASP.NET site. I tried to change the identity of sharepoint site to be that of ASP.NET site (siteuser) and error still remains and this time my sharepoint site (when browsed separately) gives 'cannot connect to configuration database'. I even tried to change the sharepoint site to point the same app-pool that ASP.NET uses but no success so far.

Please suggest.

4

There are 4 best solutions below

0
On

You should check whether this sitename http://x2009:190/ is registered in SharePoint as alternative mapping (or something like this) also it must be exactly x2009 without any .bla.bla. Also this user must have security rights to use webservices (set up in SharePoint).

1
On

Is your Asp.Net targeting 64 bit platform? If not you are bound to get that error as SharePoint 2010 requires your code to be in 64 bit.

0
On

Try to use the SPFarm account as app pool. I got this error and can't figure out what permission I need. but if I use SPFarm, it runs ok

0
On

You can't do it from ASP.NET site to SharePoint 2010 or earlier server, due to 'cross-site' security limitations. You can use the Client Object Model and access SharePoint 2010 from a managed client (Windows app) or Silverlight app, or ECMAScript in a web part on the server.

Your option from ASP.NET is to use (consume) SharePoint Web Services.

SharePoint 2013 does have a means to allow cross-site access.