Friday, March 11, 2011

The Web application at ... could not be found. Verify that you have typed the URL correctly.

Yesterday my colleague showed me this error. He was trying to open a SPSite object using a URL and hitting the following error: 

The Web application at ... 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.

This is common, and can have several causes.

1. The obvious: The URL does not exist on the farm.  

Solution: Change the URL you are loading to the correct one.  

2. The not so obvious: the code is in a console or windows application which you are now running with an account that does not have permissions to connect to the SQL server. 

Solution: either run the application as a different user or grant the user permissions on the SQL database.

3. The last but most important: the code is in a console or windows application that is compiled with platform target x86, while your SharePoint server is x64. 

Solution: set the platform target to "Any CPU".

19 comments:

  1. Thanks, option 3 solved my problem. Not sure why VS 2010 running on a 64 bit machine would default to x86 target platform. I guess it is another MS feature.

    ReplyDelete
  2. i have used u r 3rd solution it will work for when I am login with spadmin and it will not working for ordinary users.

    ReplyDelete
  3. Hey Navin, Try following code:

    SPSecurity.RunWithElevatedPrivileges(delegate()
    {
    // Open new SPSite and SPWeb object.
    // Write ur code here.
    });

    Reference link:
    http://snahta.blogspot.com/2008/08/understanding-runwithelevatedprivileges.html

    ReplyDelete
  4. Many thanks you saved me 3 hours

    ReplyDelete
  5. I received this error and it was an alternate access mapping issue.

    http://riedoh.blogspot.com/2012/04/web-application-at-httpxxxxxxxxx-could.html

    ReplyDelete
    Replies
    1. Thanks for highlighting this. I'll update my post accordingly.

      Delete
    2. Thank you! That fixed my problem.

      Delete
  6. HI

    am using web application to upload a document from local folder to sharepoint portal..for this am using asp.net web application..but am getting the same error..i.e url specfied is incorrect..How to resolve it?

    Can any one please help me out

    ReplyDelete
    Replies
    1. You might be getting FileNotFoundException. You have to do some tweaks when you want to run object model in asp.net application.
      1. VS2010 -> Properties -> .NET Framework 3.5 and run as x64 or "Any CPU"
      2. Configure the application pool to run for the .NET Framework Version v2.0 and x64. Set "Enable 32-Bit Applications" to false.
      3. VS2010 -> property page -> "Use Custom Web Server" and specify there the url of your web application in IIS7

      Delete
    2. I have changed the settings as you said.. but still am getting the same error..What to do?

      Thanks in advance

      Delete
  7. Simple workaround is to create a console application. You will not face such issues in that. is it mandatory to use asp.net application?

    ReplyDelete
  8. Syed Danish AftabJuly 15, 2012 at 11:15 AM

    thanks a bunch dude you save me. option 3 solve the problem

    ReplyDelete
  9. Thanks dude!! It saved my life as well... the option 3 did the thing....!!!

    ReplyDelete
  10. Thank you very much!! Option 3 worked for me:)

    ReplyDelete
  11. So much help thank you !

    ReplyDelete
  12. Thank you!
    I would have never bet on the target platform...
    Worked for me :)

    ReplyDelete
  13. Hey, thanks for the info.
    Problem for me was lack of permission on the SQL side.
    the service account i was using to run a scheduled task to run a script didn't have enough rights

    ReplyDelete