Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / May 2005

Tip: Looking for answers? Try searching our database.

Sharepoint (WSS) authentication issues in code/web service

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ken McAndrew - 16 May 2005 19:45 GMT
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.

Signature

Kenneth S. McAndrew
Software Developer, Information Concepts
kmcandrew@infoconcepts.com

Mike Walsh - 17 May 2005 05:10 GMT
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

> 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
[quoted text clipped - 95 lines]
> I've been trying to figure this out for a few weeks now with no success,
> so any help would be extremely appreciated. Thanks.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.