Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Services > Sharepoint (WSS) authentication issues in code/web service

Reply
Thread Tools

Sharepoint (WSS) authentication issues in code/web service

 
 
Ken McAndrew
Guest
Posts: n/a
 
      05-16-2005
I'm working with a client that has Windows Server 2003, WSS, accessed
through a custom application. In this application, we need to attach files
to cases by adding them to a database and storing them in Sharepoint. This
process works fine at our office, but the client is having authentication
problems.

The only authentication being used is Windows security. Before, my
Sharepoint code (in C#) was in a file, and the users would get a login
prompt. However, even if they entered correct information, it would not let
them in and eventually give an Unauthorized (401.1) error. I decided to move
the functionality to a web service and use the Credentials object to set up
authentication. These are the calls in my web page:

pmdtc_ws.CreateSite svcCreateSite = new PMDTC.pmdtc_ws.CreateSite();
svcCreateSite.Credentials =
System.Net.CredentialCache.DefaultCredentials;
string strResult = svcCreateSite.AttachFile(subWeb, sFileName,
pFileContents);

And this is the web service's method:

[WebMethod]
public string AttachFile(string pFolderID, string pFileName, byte[]
pFileContents)
{
string strMessage;

try
{
SPSite site = SPControl.GetContextSite(Context);
SPWeb web;// = SPControl.GetContextWeb(Context);
string tmpSite = site.Url;

if (pFolderID != "0")
{
tmpSite += "/" + pFolderID + "/";
}

tmpSite = tmpSite.Substring(7);
int posSite = tmpSite.IndexOf("/");
tmpSite = tmpSite.Substring(posSite);

web = site.OpenWeb(tmpSite);
web.AllowUnsafeUpdates = true;
SPFolder folder;
SPFile file;
folder = web.GetFolder("Shared Documents");

file = web.GetFile(folder.Url + "/" + pFileName);

if (file.Exists) ////check in existing file
{
file.CheckOut();
file.SaveBinary(pFileContents);
file.CheckIn(""); ////We have to force the checkin here.
}
else ////Add a new file
{
SPFileCollection files;
files = folder.Files;

files.Add(folder.Url + "/" + pFileName, pFileContents);
}

strMessage = "Success!";
}
catch (Exception ex)
{
strMessage = "Fail! " + ex.Message.ToString();
}

return strMessage;
}

When I run this, I get back an ASP.Net error page, that says the user is
unauthorized: 401, treating it as an unhandled exception. (As a note, users
have Contributer permissions in Sharepoint, and a cross-site group with
Contributer permissions is set up for the subsites that files might be
stored to, but this happens at any level.)

We found that if the administrator does a file attach, it will work, and
allow access to the site for a time, before it loses that access. Also, when
I used a standard user (having the problem) to access the Sharepoint site,
we got this error message:

"Error

List does not exist

The page you selected contains a list that does not exist. It may have been
deleted by another user. Click "Home" at the top of the page to return to
your Web site."

There was a fix mentioned on Google for this, giving users read access to
the webtemp.xml file in Templates/1033/XML, but that worked only until we
rebooted the machine.

I've been trying to figure this out for a few weeks now with no success, so
any help would be extremely appreciated. Thanks.

--

Kenneth S. McAndrew
Software Developer, Information Concepts
http://www.velocityreviews.com/forums/(E-Mail Removed)



 
Reply With Quote
 
 
 
 
Mike Walsh
Guest
Posts: n/a
 
      05-17-2005
Please do not post WSS Programming questions to both the WSS newsgroups.

WSS Programming questions go only to .windowsservices.development and
non-'WSS Programming' questions go only to the main newsgroup
..windowsservices

It's a useful division that saves everyone a lot of time in finding messages
they are interested in.

Thanks for your assistance with this when posting again.

(Follow-up changed)

Mike Walsh, Helsinki, Finland
WSS FAQ http://wss.collutions.com
please reply to the newsgroup only

"Ken McAndrew" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I'm working with a client that has Windows Server 2003, WSS, accessed
> through a custom application. In this application, we need to attach files
> to cases by adding them to a database and storing them in Sharepoint. This
> process works fine at our office, but the client is having authentication
> problems.
>
> The only authentication being used is Windows security. Before, my
> Sharepoint code (in C#) was in a file, and the users would get a login
> prompt. However, even if they entered correct information, it would not
> let them in and eventually give an Unauthorized (401.1) error. I decided
> to move the functionality to a web service and use the Credentials object
> to set up authentication. These are the calls in my web page:
>
> pmdtc_ws.CreateSite svcCreateSite = new PMDTC.pmdtc_ws.CreateSite();
> svcCreateSite.Credentials =
> System.Net.CredentialCache.DefaultCredentials;
> string strResult = svcCreateSite.AttachFile(subWeb, sFileName,
> pFileContents);
>
> And this is the web service's method:
>
> [WebMethod]
> public string AttachFile(string pFolderID, string pFileName, byte[]
> pFileContents)
> {
> string strMessage;
>
> try
> {
> SPSite site = SPControl.GetContextSite(Context);
> SPWeb web;// = SPControl.GetContextWeb(Context);
> string tmpSite = site.Url;
>
> if (pFolderID != "0")
> {
> tmpSite += "/" + pFolderID + "/";
> }
>
> tmpSite = tmpSite.Substring(7);
> int posSite = tmpSite.IndexOf("/");
> tmpSite = tmpSite.Substring(posSite);
>
> web = site.OpenWeb(tmpSite);
> web.AllowUnsafeUpdates = true;
> SPFolder folder;
> SPFile file;
> folder = web.GetFolder("Shared Documents");
>
> file = web.GetFile(folder.Url + "/" + pFileName);
>
> if (file.Exists) ////check in existing file
> {
> file.CheckOut();
> file.SaveBinary(pFileContents);
> file.CheckIn(""); ////We have to force the checkin here.
> }
> else ////Add a new file
> {
> SPFileCollection files;
> files = folder.Files;
>
> files.Add(folder.Url + "/" + pFileName, pFileContents);
> }
>
> strMessage = "Success!";
> }
> catch (Exception ex)
> {
> strMessage = "Fail! " + ex.Message.ToString();
> }
>
> return strMessage;
> }
>
> When I run this, I get back an ASP.Net error page, that says the user is
> unauthorized: 401, treating it as an unhandled exception. (As a note,
> users have Contributer permissions in Sharepoint, and a cross-site group
> with Contributer permissions is set up for the subsites that files might
> be stored to, but this happens at any level.)
>
> We found that if the administrator does a file attach, it will work, and
> allow access to the site for a time, before it loses that access. Also,
> when I used a standard user (having the problem) to access the Sharepoint
> site, we got this error message:
>
> "Error
>
> List does not exist
>
> The page you selected contains a list that does not exist. It may have
> been deleted by another user. Click "Home" at the top of the page to
> return to your Web site."
>
> There was a fix mentioned on Google for this, giving users read access to
> the webtemp.xml file in Templates/1033/XML, but that worked only until we
> rebooted the machine.
>
> I've been trying to figure this out for a few weeks now with no success,
> so any help would be extremely appreciated. Thanks.
>
> --
>
> Kenneth S. McAndrew
> Software Developer, Information Concepts
> (E-Mail Removed)
>
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sharepoint issues? =?Utf-8?B?S2plbGw=?= ASP .Net 2 10-17-2007 11:31 AM
MCTS Sharepoint Server or Windows Sharepoint Services RajivI MCTS 2 10-06-2007 12:13 PM
NTLM authentication against a Sharepoint Server Laurence Perl Misc 0 07-07-2005 02:33 PM
SharePoint Service could it be copied in ASP.NET Shimon Sim ASP .Net 3 05-20-2004 08:49 PM
ASP.Net Session disabled after installing SharePoint Service and BizTalk Server 2004 =?Utf-8?B?V2F5bmUgU2hlbg==?= ASP .Net 3 03-04-2004 03:01 AM



Advertisments