locked
401 UNAUTHORIZED RRS feed

  • Question

  • Hi,  

    I am new to sharepoint and was creating a sample program for my learning and after executing it when i tried to open my sharepoint site it gives me following error:

    401 UNAUTHORIZED

    This is how it happened:

    I was creating a feature receiver and on it the code was written to change the master page as:

     

            public override void FeatureActivated(SPFeatureReceiverProperties properties)
            {
                SPSite _site = (SPSite)properties.Feature.Parent;
                SPSecurity.RunWithElevatedPrivileges(delegate
                    {
                        using (SPWeb _web = _site.OpenWeb())
                        {
                            _web.AllowUnsafeUpdates = true;
                            SetMasterPage(_web, "v4CopySPLearning.master");
                        }
                    }
                );          
            }

            private void SetMasterPage(SPWeb _web, string _masterPage)
            {
                var masterUri = new Uri(_web.Url + "/_catalogs/masterpage/" + _masterPage);
                _web.MasterUrl = masterUri.AbsolutePath;
                _web.CustomMasterUrl = masterUri.AbsolutePath;
                _web.Update();
            }

    this "v4CopySPLearning.master" is my custom master page which is nothing but the copy + paste of v4.master and was placed at:

    C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATE\GLOBAL

    Then I deployed this project and when i opened my sharepoint site it gives me 401 UNAUTHORIZED error.

    Then i retracted my sharepoint solution but it didn't worked and gave me same 401 UNAUTHORIZED error.

    Then i browsed internet and found poweshell script to deploy default master page as:

    $web = Get-SPWeb http://splearning:26339/
    $web.MasterUrl = "/_catalogs/masterpage/v4.master"
    $web.Update()
    $web.Dispose()

    It got executed without error but the 401 UNAUTHORIZED error still persists.

    Any solution for the same.

    Wednesday, July 23, 2014 4:42 PM

Answers

  • Hi,

    For a better troubleshooting, I suggest you to do as follows:

    1.Try to use farm admin(System Account) to execute you code.

    2. Deactivate the Minimal Download Strategy feature. Go to Site Settings-> Site Features.

    3. Use http://localhost:26339/ instead of http://splearning:26339/ , or set Alternate Access Mapping in Central Administration.

    Thanks,
    Dennis Guo
    TechNet Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Dennis Guo
    TechNet Community Support


    • Edited by Dennis Guo Thursday, July 24, 2014 5:28 AM
    • Marked as answer by Patrick_Liang Sunday, August 3, 2014 2:49 PM
    Thursday, July 24, 2014 5:28 AM

All replies

  • Hello,

    I would suggest to open your website in sharepoint designer and set the default and custom master page to v4.master.

    Hope this help!

    Thanks,

    Wednesday, July 23, 2014 5:48 PM
  • Hi,

    For a better troubleshooting, I suggest you to do as follows:

    1.Try to use farm admin(System Account) to execute you code.

    2. Deactivate the Minimal Download Strategy feature. Go to Site Settings-> Site Features.

    3. Use http://localhost:26339/ instead of http://splearning:26339/ , or set Alternate Access Mapping in Central Administration.

    Thanks,
    Dennis Guo
    TechNet Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Dennis Guo
    TechNet Community Support


    • Edited by Dennis Guo Thursday, July 24, 2014 5:28 AM
    • Marked as answer by Patrick_Liang Sunday, August 3, 2014 2:49 PM
    Thursday, July 24, 2014 5:28 AM