/_layouts/1033/ERROR.HTM如何工作?
-
09-12-2019 - |
题
我被困,需要一个知道SharePoint Indepth的人!
编辑
这不是,而不是其他错误,如404,403等,这个错误都有一些东西!它只显示在Central Admin中有一个被封锁的文件类型时,您将通过url转到它,如 https://site.mysite.com/portal/default.asp ,ASP扩展名是一个被阻止的文件类型!然后它只向您展示错误.htm页面!如果它是default.aspx它将正常工作,因为正常的aspx不在阻塞文件类型列表 中
结束编辑
somthing正在覆盖逻辑,但我不知道什么!
假设您已阻止像SharePoint Central Admin中的ASP等文件型。
现在您进入URL并从扩展.aspx中删除,以便它是.asp
它显示标题错误的HTML页面,并表示:
以下文件已被管理员阻止: /portal/default.asp
它是从12的I /_LAYOUTS/1033/ERROR.HTM,中的HTM页面
我想重定向到自定义页面,但我不能知道正在调用错误时,所以我可以覆盖它,以便它进入自定义错误!
我已经使用以下用于重定向,但它不起作用:
.HttpContext.Current.Server.ClearError(); HttpContext.Current.Response.Clear(); strCustomAcssDndURL = getAppSettingsValue(m_SiteCollCustError + "-" + strSiteURL); HttpContext.Current.Response.Redirect(strCustomAcssDndURL, false);
但它打破了:
.HttpContext.Current.Response.Redirect();
它会抛出错误:
在已发送HTTP标头后无法重定向。
我有点困惑到什么以及甚至可能!对于任何其他错误,我得到上面的代码完美的工作!
任何帮助将极大地夸大:)
解决方案 3
int the init我创建了一个htthapplication对象,并创建了一个名为:的事件处理程序
context.EndRequest += new EventHandler(context_AcessDenied);
.
但是这个问题是它发送标题,我无法抓住它被发送的请求!所以我所做的是:
context.BeginRequest += new EventHandler(context_BeginRequest);
.
然后,我创建了甚至通过阻止列表搜索的文件范围,以便您将进入URL,如果它在列表中重定向到正确的位置:
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)
{
//
}
}
}
.
我保留了EndRequest中的其他错误处理代码,因为它应该如此工作:)。因此,由于在线没有文章,即使在MSDN上也是如此,它看起来像是这个问题的第一个解决方案:)并希望它能够帮助其他可能来到这个问题的人:)
其他提示
定义自定义错误页面是在SharePoint站点的Web.config中完成的。
如果您正在尝试在页面中重定向尝试在没有'httpcontext.crurrent'的情况下重定向
而不是在web.config中设置它,为什么您不使用SharePoint对象模型?
这是我过去使用的powershell脚本来设置自定义错误页面:
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)
.
您可以使用 SPWebApplication.SPCustomPage
enum 。只需更改第二行的部分(如“::Error
”)以表示相应的枚举。