how does /_layouts/1033/error.htm work?
-
09-12-2019 - |
Question
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 :)
Solution 3
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 :)
OTHER TIPS
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'
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.