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:


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;
                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;

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 $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.

2 Answers 2


Did you create a backup? I would restore in CA(central administration). Otherwise apply the default master page to your site for the meantime(so there is something to work with) and research your idea before implementing it. I use a pseudo subsite as my practice environment


I happen to have code in front of me that I am using to update the master pages in a feature activation event receiver, it looks like this:

var site = properties.Feature.Parent as SPSite;
var web = site.RootWeb;

var rootUrl = web.Url;
var customMasterUrl = new Uri(rootUrl + "/_catalogs/masterpage/cusom.master");
var systemMasterUrl = new Uri(rootUrl + "/_catalogs/masterpage/v4_custom.master");
//Site Master Page 
web.CustomMasterUrl = customMasterUrl.AbsolutePath;
//System Master Page 
web.MasterUrl = systemMasterUrl.AbsolutePath;

I've used this method in several features to set custom master pages without issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.