Hi,
There were certain security urls where only site collection administrator should view.
Non site collection administrator should get AccessDenied Page of the site collection.
To achieve this, we have written the below code in the class library as below
public class Redirect : IHttpModule
{
public void Init(HttpApplication context)
{
context. PreRequestHandlerExecute += new EventHandler( ProcessRequestHandler);
}
private static void OnPreSendRequestHeaders(object sender, EventArgs eventArgs)
{
}
private void ProcessRequestHandler(object sender, EventArgs e)
{
try
{
//using (StreamWriter writer = new StreamWriter("C:\\log.txt", true))
//{
//writer.WriteLine(System. DateTime.Now);
HttpApplication context = (HttpApplication)sender;
string requestUrl = Convert.ToString(context. Request.Url);
string strAbsoluteUri = context.Request.Url. AbsoluteUri.ToLower();
// check if request is accessing aspx page
if (strAbsoluteUri.Contains("/_ layouts/15/sitemanager.aspx") || strAbsoluteUri.Contains("/_ layouts/15/savetmpl.aspx") || strAbsoluteUri.Contains("/_ layouts/15/mngsiteadmin.aspx") || strAbsoluteUri.Contains("/_ layouts/15/mngsubwebs.aspx") || strAbsoluteUri.Contains("/_ layouts/15/ sitedirectorysettings.aspx") || strAbsoluteUri.Contains("/_ layouts/15/mngctype.aspx") || strAbsoluteUri.Contains("/_ layouts/15/adminrecyclebin. aspx") || strAbsoluteUri.Contains("/_ layouts/15/ areanavigationsettings.aspx") || strAbsoluteUri.Contains("/_ layouts/15/user.aspx") || strAbsoluteUri.Contains("/_ layouts/15/spusageweb.aspx") || strAbsoluteUri.Contains("/_ layouts/15/subedit.aspx") || strAbsoluteUri.Contains("/_ layouts/15/subchoos.aspx") || strAbsoluteUri.Contains("/_ catalogs/wt/forms/common.aspx" ) || strAbsoluteUri.Contains("/_ catalogs/wt/forms/allitems. aspx") || strAbsoluteUri.Contains("/_ layouts/15/mngfield.aspx") || strAbsoluteUri.Contains("/_ catalogs/lt/forms/allitems. aspx") || strAbsoluteUri.Contains("/_ catalogs/theme/forms/allitems. aspx") || strAbsoluteUri.Contains("/_ catalogs/wp/forms/allitems. aspx") || strAbsoluteUri.Contains("/_ catalogs/solutions/") || strAbsoluteUri.Contains("/_ layouts/15/ sharepointdesignersettings. aspx") || strAbsoluteUri.Contains("/_ layouts/15/areawelcomepage. aspx") || strAbsoluteUri.Contains("/_ layouts/15/ areatemplatesettings.aspx") || strAbsoluteUri.Contains("? pageview=shared&toolpaneview= 2") || strAbsoluteUri.Contains("/_ catalogs/users/simple.aspx") || strAbsoluteUri.Contains("/_ layouts/15/newsbweb.aspx") || strAbsoluteUri.Contains("/_ layouts/15/create.aspx") || strAbsoluteUri.Contains("/_ layouts/15/spcf.aspx") || strAbsoluteUri.Contains("/_ layouts/15/appregnew.aspx") || strAbsoluteUri.Contains("/_ layouts/15/srchvis.aspx") || strAbsoluteUri.Contains("/_ layouts/15/spcontnt.aspx") || strAbsoluteUri.Contains("/_ layouts/15/role.aspx") || strAbsoluteUri.Contains("/_ layouts/15/createpage.aspx") || strAbsoluteUri.Contains("/_ layouts/15/sitesubs.aspx") || strAbsoluteUri.Contains("/_ layouts/15/prjsetng.aspx") || strAbsoluteUri.Contains("/_ layouts/15/bpcf.aspx") || strAbsoluteUri.Contains("/_ layouts/15/mcontent.aspx") || strAbsoluteUri.Contains("/_ layouts/15/people.aspx") || strAbsoluteUri.Contains("/_ layouts/15/viewlsts.aspx") || strAbsoluteUri.Contains("/_ layouts/15/recyclebin.aspx") || strAbsoluteUri.Contains("/_ catalogs/masterpage/forms/ allitems.aspx") || strAbsoluteUri.Contains("/_ layouts/15/user.aspx") || strAbsoluteUri.Contains("/_ layouts/15/groups.aspx") || strAbsoluteUri.Contains("/_ layouts/15/managefeatures. aspx") || strAbsoluteUri.Contains("/_ layouts/15/ changesitemasterpage.aspx") || strAbsoluteUri.Contains("/_ layouts/15/settings.aspx"))
{
using (SPSite site = new SPSite(SPContext.Current.Site. Url.ToString()))
{
using (SPWeb web = site.OpenWeb())
{
}
}
}
}
//writer.WriteLine(System. DateTime.Now);
//}
}
catch (Exception ex)
{
}
}
private void redirectToRegistrationPage(Htt pApplication context)
{
context.Response.Redirect(SPCo ntext.Current.Web.Url. ToString() + "/_layouts/15/AccessDenied. aspx");
}
public void Dispose()
{
}
}
Deployment
1) Copied and Pasted the dll into the bin folder of the web application
2) Update the below in the web app web config under modules section in the below format
<add name="solutionname" type=" solutionname.classname, solutionname " />
Now non site collection administrators get the current site collection Access Denied Page as below
No comments:
Post a Comment