1
votes

I created a Web Application called testwebapp and then a site collection (testsite). When I try siteCollection = new SPSite("http://localhost"); in Visual Studio 2008 it throws an error Web Application is not found. Of course, the localhost works in IE and I don't know why testwebapp doesn't work. Any ideas? TIA!

David

2

2 Answers

0
votes

We saw a weird behavior like this once. Try putting a trailing slash on the end of the url when instantiating the site.

siteCollection = new SPSite("http://localhost/");

The problem we saw was that there were 2 web applications essentially sitting at the same url. One was completely hidden and it would be hit when we left the trailing slash off. Maybe you have some weirdness going on like that if you've deleted the root web application and added it back in?

0
votes

Try giving the proper url instead of using localhost. So if your machine name is mymachine use:

siteCollection = new SPSite("http://mymachine/"); 

This should work.