Error: The Web application at http://...sitename.../ could not be - Ax

12-Jun-07 04:28:00
Hello all,

I have the following problem. I wrote the web application using ASP.NET
using SharePoint model. Everything looked good and worked fine when I tested
the application using the administrator account. Then when I put the web
application live and tested it using regular user account the application is
not working and throw following error right at the begining:

The Web application at http://...sitename.../ 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.

The code that throws this error looks like following:

SPSite siteCollection = new SPSite("http://...sitename...");

I can see the Sharepoint website http://...sitename... normaly in Explorer
using the same account. Obviously it is some problem with the access rights.
I googled the web and find a lot of suggestions. For example the fololowing
ones:

http://support.microsoft.com/?kbid=832816
http://forums.microsoft.com/TechNet/ShowPost.aspx?PostID=1125480&SiteID=17
http://forums.microsoft.com/TechNet/ShowPost.aspx?PostID=1125480&SiteID=17
http://jack.whyyoung.com/tags/MOSS-Problem-web-application-object-mode.htm
http://www.kbalertz.com/kb_935751.aspx
https://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=726395&SiteID=1
http://www.microsoft.com/technet/community/newsgroups/dgbrowser/en-us/default.mspx?dg=microsoft.public.sharepoint.development_and_programming&tid=73f12d49-07d4-4282-99ac-140110255bba&cat=en-us-technet-sharepoint&lang=en&cr=US&sloc=en-us&m=1&p=1

I followd all the instructions there but nothing helped. I used the same
applicatipn pool ID for website, created new one with different access
rights, added access for account ASPNET and NETWORK SERVICES for sharepoint
site and in SQL server, but no success - same error over and over. I am
already desparate. Intiristing is that if I log to the computer with
administrator account and then log to sharepoint as regular user it works
fine. However as soon as I log to the computer as regular user, the error is
there again. I do not understand it at all, I thought web application runs on
the server and IIS is taking care of access rights no matter how I am logged
to the computer.

What I have also found is that if I add user group Domain Users in WSS
Central Administration to the list Central Adminstration -> Application
Mangement -> Policy For web application  and give it the right to "read all"
(only option regarding reading there) then it works and the error is not
there anymore. However Sharepoint then starts to ignore lower access right
specified on lists,  document libraries and folders and users can see and
browse everything on sharepoint site regardless the settings in sharepoint.
So this is not accaptable solution for me. However I cannot specify in
Central Adminstration -> Application Mangement -> Policy For web application
to see only something.

Does anybody has any idea how to solve this? Any help would be highly
appreciated.

Thanks for any info in advance.

Roman
button
 
 

Error: The Web application at http://...sitename.../ could not be - Ax

12-Jun-07 07:10:01
Well, I was somehow able to obey the problem using the following code:

SPSecurity.RunWithElevatedPrivileges(delegate()
{
// Opening sharepoint server at the relevant address
using (Site = new SPSite("http://...sitename..."))
{
// main code to work with sharepoint
}
});

The application at least starts and opens and I thought I won. However I was
happy too soon. It seems that there is no possible to insert, update and
delete lists items in this mode as the following code which works before
(when logged as administrator, otherwise I could not reach it) throws the
exceptions:

Guid listGuid = new
Guid("0f4ec74e-3338-4ff9-991b-1b8a83af56a7");
SPList list = lists[listGuid];
SPListItemCollection items = list.Items;
SPListItem listItem = items.Add();
rowNo++;
listItem[0] = idNo.Text;
listItem[1] = rowNo;
listItem[2] = description.Text;
listItem[3] = qtyNum;
listItem[4] = unit.SelectedValue;
listItem[5] = priceNum;
listItem[6] = currency.SelectedValue;
listItem.Update();

throws the excepion at the last line when Update() is applied:

System.InvalidOperationException: Operation is not valid due to the current
state of the object. at

Microsoft.SharePoint.WebControls.SPControl.SPWebEnsureSPControl(HttpContext
context) +138
Microsoft.SharePoint.WebControls.SPControl.GetContextWeb(HttpContext context)
+25 Microsoft.SharePoint.SPContext.get_Current() +106
Microsoft.SharePoint.SPListItem.GetValue(SPField fld, Int32 columnNumber,
Boolean bRaw) +440 Microsoft.SharePoint.SPListItem.GetValue(String strName,
Boolean bThrowException) +84 Microsoft.SharePoint.SPListItem.GetValue(String
strName) +32 Microsoft.SharePoint.SPListItem.InitItemID() +48
Microsoft.SharePoint.SPListItem.get_ID() +32
Microsoft.SharePoint.SPListItem.AddOrUpdateItem(Boolean

So I am where I was before. Any suggestions? Please help .... Thank you very
mych in advance for any information.

Roman
button
 

Error: The Web application at http://...sitename.../ could not be - Steven Van de Craen

12-Jun-07 07:21:53
The SPSite object will be disposed as soon as you exit the 'using' clause.
Any SPList or SPListItem objects that we're instantiated using the SPSite
object will be invalid. Make sure this isn't the case !

Steven
button
 

Error: The Web application at http://...sitename.../ could not - Ax

13-Jun-07 03:04:01
Hello Steven,

Thanks for the input but this is not the case. It is all inside 'using'
clause. The full script looks like this:

SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite siteCollection = new
SPSite("http://sharepoint"))
{
SPWebCollection sites = siteCollection.AllWebs;
SPWeb site = sites[0];
SPListCollection lists = site.Lists;
string userName =
HttpContext.Current.User.Identity.Name.ToString();
site.AllowUnsafeUpdates = true;
Guid listGuid = new
Guid("0f4ec74e-3338-4ff9-991b-1b8a83af56a7");
SPList list = lists[listGuid];
SPListItemCollection items = list.Items;
SPListItem listItem = items.Add();
rowNo++;
listItem[0] = idNo.Text;
listItem[1] = rowNo;
listItem[2] = description.Text;
listItem[3] = qtyNum;
listItem[4] = unit.SelectedValue;
listItem[5] = priceNum;
listItem[6] = currency.SelectedValue;
listItem.Update();
}
});

So it is inside. However the line listItem.Update() throws the exception
mentioned above.

Thanks,

Roman
button
 

Error: The Web application at http://...sitename.../ could not be - Ax

13-Jun-07 08:14:00
Hmmm,  interesting. I have finally found the solution and it is quite easy. I
want almost cry when I realize that I've spent three days searching the
Internet and trying different solutions. I had to write maybe 20 MB of code
not believe it will work, but miraculously it does.

The only thing to do is to get SPSite in RunWithElevatedPrivileges relation
and then close RunWithElevatedPrivileges and the rest of the code to update
put behind that.

So the following code:

SPSite site = null;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
site = new SPSite("http://sharepointsrv"))
});
... some other code ....
Guid listGuid = new Guid("0f4ec74e-3338-4ff9-991b-1b8a83af56a7");
SPList list = lists[listGuid];
SPListItemCollection items = list.Items;
SPListItem listItem = items.Add();
rowNo++;
listItem[0] = idNo.Text;
listItem[1] = rowNo;
listItem[2] = description.Text;
listItem[3] = qtyNum;
listItem[4] = unit.SelectedValue;
listItem[5] = priceNum;
listItemDevil <img src="/> = currency.SelectedValue;
listItem.Update();

... works beautifully. The Udate comes through without throwing the
exception and everything is right. Wow, how easy. :) I am really narky that I
have spent so much time solving this but happy at the same time that it
works. I do not know which feeling dominates right now - well probably the
happiness. :)))

Roman
button
 

Error: The Web application at http://...sitename.../ could not be - Jussi

27-Jun-07 09:18:05
Thank you Axl, after so many hours trying to solve this problem I
finally managed to update my list item.
button
 

Error: The Web application at http://...sitename.../ could not - Ax

27-Jun-07 09:38:01
You are welcome. I am happy that it helped somebody because it was driving me
crazy and I could not find any solution on the web. I spent eternity on that
but finally found the solution and it is what counts. :)

Thanks also,

Roman
button
 
Add a feature in Central Admin feature lists ???