Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am stuck and need someone who knows sharepoint indepth!

EDIT

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

END EDIT

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:

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

but it breaks on:

HttpContext.Current.Response.Redirect();

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 :)

share|improve this question

3 Answers 3

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'

share|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 Sharepoint 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 Sharepoint 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:

2007:

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

2010:

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

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.

share|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 Sharepoint 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 Sharepoint Sep 28 '12 at 15:22
up vote 0 down vote accepted

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;
            try
            {
                if (coll.Contains(extension))
                {
                    strSiteURL = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority); 
                    HttpContext.Current.Server.ClearError();
                    HttpContext.Current.Response.Clear();
                    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 :)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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