I am stuck and need someone who knows sharepoint indepth!


This is not, not for other errors like 404, 403 ect, this error is somthing else! it only shows when you have a blocked file type in central admin and you go to that blocked extension by url like https://site.mysite.com/portal/default.asp, the asp extension is a blocked file type! it will then show you the error.htm page only! if it were default.aspx it would work as normal becasue aspx is not in the blocked file type list


somthing is overwriting the logic but i dont know what!

Say you have blocked a filetype like asp in sharepoint central admin.

Now you go onto the url and remove from the extention .aspx so that it is .asp

It shows a html page with the title error and says:

The following file(s) have been blocked by the administrator: /portal/default.asp

It is taking that htm page from 12hive located at /_layouts/1033/error.htm ,

I would like to redirect to a custom page but I cant and need to know where that error.htm is being called so I can overwrite it so that it goes to a custom error.aspx page instead!

I have used the following to redirect but it doesnt work:

strCustomAcssDndURL = getAppSettingsValue(m_SiteCollCustError + "-" + strSiteURL);
HttpContext.Current.Response.Redirect(strCustomAcssDndURL, false);

but it breaks on:


It throws an error:

Cannot redirect after HTTP headers have been sent.

I am a bit confused as to what to do and if its even possible! For any other error that i get the code above works perfectly!

Any help would be greatly appriciated :)


Defining a custom error page is done in the web.config of your SharePoint site.

If your are trying to redirect in a page try redirecting without the 'HttpContext.Current'

| improve this answer | |
  • First of all the redirecting as i stated in my question already uses the web.config for other errors like 404 and 403 (httpmodule). but this is different and you cannot take out 'HttpContext.Current' as it wont work ;) thanks for your help tho – Ali Jafer Sep 28 '12 at 13:21
  • The proper way to redirect in SharePoint is SPUtility.Redirect. So yes, @almostSharepointMaster, you can take out HttpContext.Current... – RJ Cuthbertson Sep 28 '12 at 14:11
  • yes your right the proper way is to use SPUtility.Redirect. But like i said it doesnt work as somthing in sharepoint is overwriting the logic hence why i cant use both methods! thanks for your answer tho :) – Ali Jafer Sep 28 '12 at 15:07

Instead of setting this in web.config, why don't you use the SharePoint Object Model for this?

Here's a PowerShell script I've used in the past to set a custom error page:


$webapp = [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup("http://thewebapp")
$webapp.UpdateMappedPage([Microsoft.SharePoint.Administration.SPWebApplication+SPCustomPage]::Error, "/_layouts/yourerrorpage.html")


$webapp = Get-SPWebApplication "http://thewebapp"
$webapp.UpdateMappedPage([Microsoft.SharePoint.Administration.SPWebApplication+SPCustomPage]::Error, "/_layouts/yourerrorpage.html")

You can set different types of errors this way using the SPWebApplication.SPCustomPage enum. Just change the portion of the second line (like "::Error") to represent the appropriate enum.

| improve this answer | |
  • It wont work, You can try it yourself! just block asp in central admin and do the above settings and it will still take you to the error.htm! I dont know where the logic is comming from and what is calling it! I have already done the redirection for other errors that use the object model according to msdn! thats not the issue! – Ali Jafer Sep 28 '12 at 15:13
  • Just breathe. It will be alright. – RJ Cuthbertson Sep 28 '12 at 15:17
  • lol i know, just been spending all day on this is driving me mad ;) . Its not documented anywhere aswell and no one seem to know about it for some reason! i dont know if its just a limitation to sharepoint? – Ali Jafer Sep 28 '12 at 15:22

Ok iv figured it out:

int the init i created a HttpApplication object and created an event handler called:

context.EndRequest += new EventHandler(context_AcessDenied);

but this issue was it was sending the header and I was unable to catch the request befor it gets sent off! So what I did was the following:

context.BeginRequest += new EventHandler(context_BeginRequest);

I then created the even that searches through the blocked list for file extentions that you would enter into the url and if its in the list to redirect to the right location:

    private void context_BeginRequest(object sender, EventArgs e)
        HttpApplication httpApp = sender as HttpApplication;
        HttpContext context = httpApp.Context;
        string httpUrl = context.Request.Url.ToString();
        string strCustomAcssDndURL = string.Empty;
        string strSiteURL = string.Empty;

        if (!httpUrl.ToLower().Equals(null) && !httpUrl.ToLower().Contains("/_layouts/"))
            string[] breakURL = httpUrl.Split('.');
            int count = breakURL.Length - 1;
            string extension = breakURL[count].ToString();

            Uri siteUrl = new Uri(httpUrl);
            SPWebApplication webApplication = SPWebApplication.Lookup(siteUrl); ;
            Collection<string> coll = webApplication.BlockedFileExtensions;
                if (coll.Contains(extension))
                    strSiteURL = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority); 
                    strCustomAcssDndURL = getAppSettingsValue(m_SiteCollCustError + "-" + strSiteURL);
                    HttpContext.Current.Response.Redirect(strCustomAcssDndURL, false);
            catch (Exception a)

I kept the other error handling code within the EndRequest as it was working as it should :). So as there is not articles online what so ever on this subject even on msdn it looks like the first solution to this problem :) and hope it helps others that might come accross this issue :)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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