Sharepoint (WSS) authentication issues in code/web service

Discussion in 'ASP .Net Web Services' started by Ken McAndrew, May 16, 2005.

  1. Ken McAndrew

    Ken McAndrew Guest

    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
    Ken McAndrew, May 16, 2005
    #1
    1. Advertising

  2. Ken McAndrew

    Mike Walsh Guest

    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" <> wrote in message
    news:...
    > 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
    >
    >
    >
    >
    Mike Walsh, May 17, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. laks
    Replies:
    0
    Views:
    421
  2. Dennis Dobslaf

    Forms authentication and WSS

    Dennis Dobslaf, Feb 24, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    320
    Dennis Dobslaf
    Feb 24, 2005
  3. GaryDean

    SharePoint WSS Question

    GaryDean, Jun 10, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    317
    Steven Cheng[MSFT]
    Jun 11, 2007
  4. Matt Fitzmaurice

    Windows SharePoint Services (WSS)

    Matt Fitzmaurice, Sep 11, 2003, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    118
    Matt Fitzmaurice
    Sep 11, 2003
  5. Sven W.
    Replies:
    1
    Views:
    141
    Bob Barrows [MVP]
    Jan 20, 2008
Loading...

Share This Page