locked
Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) -Accessing the sharepoint site RRS feed

  • Question

  •  

    Hi,

     

       I have developed a custom workflow and deployed to my sharepoint server. I am calling the workflow from a Web application (ASP.NET & C#).

     

    The code in the web applicaltion is as follows:

     

                site = new SPSite(http://servername/sites/banusite);

                web = site.OpenWeb();

                            CreateItem();

     

            public string CreateItem()

            {

                try

                {         

                    SPList EScienceList = web.Lists[ListName];

                    SPListItemCollection fundApplicationItems = web.Lists[ListName].Items;

                    SPListItem newFundApp = fundApplicationItems.Add();

     

                    newFundApp["ApplicationID"] = "TEstData11"; // Need to take from UI

                    newFundApp["ApplicantName"] = "TEstData33"; // Need to take from UI

                    newFundApp["FundType"] = "TEstData"; // Need to take from UI            

     

                    newFundApp.Update();

     

                    StartWorkFolw(newFundApp,EScienceList,site); //My own function to start the WF

     

                    return "Success";

                }

                catch (Exception Ex)

                {

                    return Ex.Message;}

     

    When i run the application from Visualstudio, on the sharepoint server machine, it is working fine..

    The url of the web site is http://localhost:1497/testsite/default.aspx. But when i tried to call it from out side with IP address (eg http://10.1.25.171/testsite/default.aspx)  i am getting error like

     

    The URL http://servername/sites/banusite 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.

     

    I tried the following:

     

      1. I have changed the sharepoint url with IP address.

         Eg: http://10.1.25.171/sites/banusite

        

         Err:

    The URL http://servername/sites/banusite 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.

     

      2. I passed the user token to the SPSite class, while creating the SPSite object. The code is as follows:

     

     //This is to get the user token from UserGroup WebService //Sharepoint webservice

     

    private SPUserToken GetUserToken()

            {

                UserGroup.UserGroup usergrp = new UserGroup.UserGroup();

                usergrp.PreAuthenticate = true;

                usergrp.Credentials = new NetworkCredential("banu", "123");

                usergrp.Url = siteURL + @"/_vti_bin/UserGroup.asmx";

     

                XmlNode userColl = usergrp.GetAllUserCollectionFromWeb();

     

    // retrieves the //exact SPID for the user name

    string token = userColl.FirstChild.ChildNodes[5].Attributes["Sid"].Value;

     

                byte[] dBytes;

               

                System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();

                dBytes = enc.GetBytes(token);

     

                SPUserToken token1 = new SPUserToken(dBytes);

                return token1;

            }

     

     

    //Main code

     

                SPUserToken userToken = GetUserToken();

                site = new SPSite(siteURL, userTokens);

                web = site.OpenWeb();

     

     

    After passing the user token when I tried to access the TestSite from outside I got error like

     

              “Value does not fall within the expected range”.

     

    When check the error, I it is not creating the SPWeb object also. All the details in the web object contain exceptions.

     

    3. I read it could happen because of the permissions. Then I tried with the following code:

     

    SPSite mysite = null;

     

                SPSecurity.RunWithElevatedPrivileges(delegate()

                {

                     mysite = new SPSite("http://localsps:8888/sites/banusite");

     

                });

               

                mysite.CatchAccessDeniedException = false;

                web = mysite.RootWeb;

     

    Then also I got the error like

     

    “Value does not fall within the expected range”.

     

    4. Then I tried the following steps:

     

        IIS -> LocalComputer -> Application Pools -> Default Applicationpool -> Properties -> Identity tab -> applicationpool Identity -> Predefined -> changed to ‘Local System’ from ‘Network Service’

     

        Still error.

     

    5. As the last attempt I have given the anonymous access to the SharePoint site (http://servername/sites/banusite). When I tried to access using IP address (http://10.1.25.171/testsite1/default.aspx) I got Error like

     

    Server Error in '/TestSite1' Application.


    Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

    ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate="true"/>, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.

    To grant ASP.NET access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.

    Source Error:

     
    Line 78:                 ////newFundApp["Fund Type"] = "TEstData"; // Need to take from UI            
    Line 79: 
    Line 80:                 newFundApp.Update();
    Line 81: 
    Line 82:                 //StartWorkFolw(newFundApp,EScienceList,site);


    Source File: C:\DevProject\TFS\Workflow\07-09-2007-1030\My.Mimos.Workflow.User.ServImpl\My.Mimos.Workflow.ServImpl\My.Mimos.Workflow.ServImpl\clsWFUserOperationsImpl.cs    Line: 80

    Stack Trace:

     
    [UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))]
       Microsoft.SharePoint.SPGlobal.HandleUnauthorizedAccessException(UnauthorizedAccessException ex) +50
       Microsoft.SharePoint.Library.SPRequest.AddOrUpdateItem(String bstrUrl, String bstrListName, Boolean bAdd, Boolean bSystemUpdate, Boolean bPreserveItemVersion, Boolean bUpdateNoVersion, Int32& plID, String& pbstrGuid, Guid pbstrNewDocId, Boolean bHasNewDocId, String bstrVersion, Object& pvarAttachmentNames, Object& pvarAttachmentContents, Object& pvarProperties, Boolean bCheckOut, Boolean bCheckin, Boolean bMigration, Boolean bPublish) +254
       Microsoft.SharePoint.SPListItem.AddOrUpdateItem(Boolean bAdd, Boolean bSystem, Boolean bPreserveItemVersion, Boolean bNoVersion, Boolean bMigration, Boolean bPublish, Boolean bCheckOut, Boolean bCheckin, Guid newGuidOnAdd, Int32& ulID, Object& objAttachmentNames, Object& objAttachmentContents, Boolean suppressAfterEvents) +746
       Microsoft.SharePoint.SPListItem.UpdateInternal(Boolean bSystem, Boolean bPreserveItemVersion, Guid newGuidOnAdd, Boolean bMigration, Boolean bPublish, Boolean bNoVersion, Boolean bCheckOut, Boolean bCheckin, Boolean suppressAfterEvents) +166
       Microsoft.SharePoint.SPListItem.Update() +89
       My.Mimos.Workflow.ServImpl.clsWFUserOperationsImpl.CreateItem(String ApplicationID, String ApplicantName, String FundType, DateTime AppliedDate) in C:\DevProject\TFS\Workflow\07-09-2007-1030\My.Mimos.Workflow.User.ServImpl\My.Mimos.Workflow.ServImpl\My.Mimos.Workflow.ServImpl\clsWFUserOperationsImpl.cs:80
       _Default.Button1_Click(Object sender, EventArgs e) in c:\Inetpub\wwwroot\TestSite1\Default.aspx.cs:46
       System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
       System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107
       System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102

     


    Version Information: Microsoft .NET Framework Version:2.0.50727.832; ASP.NET Version:2.0.50727.832

     

     

    5. I have tried the dcomconfg also

     

    Pls help me in resolving this issue. i have tried all most all the ways.

     

    Thanks and regards,

    Banu

    Thursday, September 20, 2007 6:37 AM

Answers

  • Hi Banu,
    I see that this is a rather old post, but I only came across it today.
    I notice 3 things:

    1-When you replace your servername with IP address, remember that you still need to specify the port.
    Example: You replaced is http://localhost:1497/testsite/default.aspx with http://10.1.25.171/testsite/default.aspx. This is wrong as the port number is no longer specified. Always remember to include the port.
    Example: http://localhost:1497/testsite/default.aspx can be replaced with http://10.1.25.171:1497/testsite/default.aspx 

    2-You can check the firewall settings on the server.

    3-When you use the SPListItem.Update(); method, remember to set the AllowUnsafeUpdates.
    Example:

    contractweb.AllowUnsafeUpdates =

    true;

    item.Update();

    contractweb.AllowUnsafeUpdates =

    false;

    I hope this helps, if too late for you, hopefully in time for someone else.

    Regards
    Johan

    Tuesday, December 29, 2009 3:16 PM
  • Hi,

    Write your code in the following line : 

    SPWeb MyWeb = null;

    try
    {
           SpSecurity.runwithelevatedprivilidges(delegate()

            using(SpSite Mysite = new SPsite("Your Site URL"))
              {
                  MyWeb = MySite.OpenWeb();
              });

                //Your code here
    }

    catch
    {
    }

    finally
    {
       MyWeb.dispose();
    }

    Like this your code will run under administrator rights and it will not show the above error. I got the same error once and rectified it by writing this.

    Regards
    Ginni
    Wednesday, December 30, 2009 6:17 AM
  • I had a similar issue.

     

    I created a feature that receive parameters of a item (itemAdded) and creates an item in an other list automatically.

    every time this feature active, I had the same error: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).

     

    Thanks JohanOlivier and Ginni Sharma.  I solve this problem  with both solutions.

     

    public override void ItemAdded(SPItemEventProperties properties)
    {
        SPListItem firstItem = properties.ListItem;
        string name = firstItem["Title"].ToString();

        SPSecurity.RunWithElevatedPrivileges(delegate()
        {

            SPSite site = new SPSite("my site");

            site.AllowUnsafeUpdates = true;
            SPWeb web = site.OpenWeb();

            SPList list = web.Lists["other list"];

            SPListItem secondItem = list.Items.Add();

            secondItem["Title"] = name;

            item.Update();
            list.Update();


            site.AllowUnsafeUpdates = false;
        });
    }

     

    Thanks again :)

    Thiago Romam

    • Marked as answer by Mike Walsh FIN Sunday, December 26, 2010 12:37 PM
    Friday, April 16, 2010 11:34 AM

All replies

  • Did u solve ur issue... I have the same problem.

     

    Monday, November 19, 2007 10:26 PM
  • I had this issue when running the Infrastucture Updates for Sharepoint. The cause of it in my case was a corrupt database or database with faulty permissions. When I viewed the c:\program files\common files\microsoft shared\web server extensions\12\logs\upgrade.log I found references to a database which said 'Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)'. It didn't seem to be an SQL permissions issue and all the permissions in Sharepoint seemed OK, yet for whatever reason, it could not access it during the upgrade. What I did was as follows.
    • Deteched the database using Central Admin, Application Management, Content Databases (click on the database, click in the 'Detach Database' check box, then click OK). This does not delete the database from SQL, just detaches it from Sharepoint.
    • Run the Install and Config Wizard which should complete OK.
    • Re-attach databse using Application Management, Content Databases, Attach Database (just enter the database name here and it will go and find it if it exists).
    • Then re-ran the Install and Config Wizard, which worked again.
    • Later I decided that I didn't need the contents of this database, so I deleted and re-created it, then ran the Install & Config Wizard again just to be on the safe side. Obviously, that might not be an option for you if you need what is in there so I wouldn't recommend this unless you are 100% certain that you don't need it.

    What you can do before hand if you think this might be the issue is to just detach a database and then re-attach it. If it is the same issue, then when you re-attach it, it uses the upgrade.log to record it activity during the re-attach, so if it is the same issue, it will be recorded here.

    Thanks

    • Proposed as answer by Mattaniah Thursday, August 19, 2010 2:40 PM
    Thursday, March 19, 2009 9:03 AM
  • Hi

    Could you maybe explain where is "outside" but I will assume you require the application to be accessible from "outside" of your org. In saying that, could I perhaps propose you take a look at this link http://technet.microsoft.com/en-us/library/cc262201.aspx, it refers to Forms Based Authentication (FBA) which allows Anonymous User to login with a username and password to your application, this might be the cause for your application returning a "Access is denied" exception. Also the database might not be configured to recognise the aspnet/networkservice/iusr_servername user(s), that a asp.net application automatically assumes. In any case if I assume wrong good luck to anyone else
    http://www.myheritage.co.za http://www.schoolsearch.co.za
    • Edited by Sabata Mereeotlhe Tuesday, October 6, 2009 11:38 AM Remembered something extra
    Tuesday, October 6, 2009 11:35 AM
  • Hi Banu,
    I see that this is a rather old post, but I only came across it today.
    I notice 3 things:

    1-When you replace your servername with IP address, remember that you still need to specify the port.
    Example: You replaced is http://localhost:1497/testsite/default.aspx with http://10.1.25.171/testsite/default.aspx. This is wrong as the port number is no longer specified. Always remember to include the port.
    Example: http://localhost:1497/testsite/default.aspx can be replaced with http://10.1.25.171:1497/testsite/default.aspx 

    2-You can check the firewall settings on the server.

    3-When you use the SPListItem.Update(); method, remember to set the AllowUnsafeUpdates.
    Example:

    contractweb.AllowUnsafeUpdates =

    true;

    item.Update();

    contractweb.AllowUnsafeUpdates =

    false;

    I hope this helps, if too late for you, hopefully in time for someone else.

    Regards
    Johan

    Tuesday, December 29, 2009 3:16 PM
  • Hi,

    Write your code in the following line : 

    SPWeb MyWeb = null;

    try
    {
           SpSecurity.runwithelevatedprivilidges(delegate()

            using(SpSite Mysite = new SPsite("Your Site URL"))
              {
                  MyWeb = MySite.OpenWeb();
              });

                //Your code here
    }

    catch
    {
    }

    finally
    {
       MyWeb.dispose();
    }

    Like this your code will run under administrator rights and it will not show the above error. I got the same error once and rectified it by writing this.

    Regards
    Ginni
    Wednesday, December 30, 2009 6:17 AM
  • Hi ,

    I think that you need to run the code in elevated privilege as Ginni indicated. The web should be also opened inside the Elevate privilege.

     

    SPSecurity.RunWithElevatedPrivileges(delegate() {
    
    using (SPSite site =new SPSite("Your site")) {
    
    using (SPWeb web=site.OpenWeb(){
    
    
    }
    
    }
    });
    Thursday, February 18, 2010 9:45 PM
  • I had a similar issue.

     

    I created a feature that receive parameters of a item (itemAdded) and creates an item in an other list automatically.

    every time this feature active, I had the same error: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).

     

    Thanks JohanOlivier and Ginni Sharma.  I solve this problem  with both solutions.

     

    public override void ItemAdded(SPItemEventProperties properties)
    {
        SPListItem firstItem = properties.ListItem;
        string name = firstItem["Title"].ToString();

        SPSecurity.RunWithElevatedPrivileges(delegate()
        {

            SPSite site = new SPSite("my site");

            site.AllowUnsafeUpdates = true;
            SPWeb web = site.OpenWeb();

            SPList list = web.Lists["other list"];

            SPListItem secondItem = list.Items.Add();

            secondItem["Title"] = name;

            item.Update();
            list.Update();


            site.AllowUnsafeUpdates = false;
        });
    }

     

    Thanks again :)

    Thiago Romam

    • Marked as answer by Mike Walsh FIN Sunday, December 26, 2010 12:37 PM
    Friday, April 16, 2010 11:34 AM