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