Sitefinity 8 中的错误页面重定向
Error Page redirect in Sitefinity 8
在我尝试将 webconfig 更改为 Sitefinity 论坛中的示例之后,我遇到了关于 404 页面的 Sitefinity 问题,但它不起作用。对我有什么想法吗?
我想你不能在网络配置中设置它,我试过并找到了另一种解决方案。所以请检查下面的代码并将其放入您的 globar.asax
int statusCode = Context.Response.StatusCode;
if ((Context.Response.StatusCode == 404 || Context.Response.StatusCode == 400) && Request.Path != (ApplicationConfig.Instance.PrefixLang + "/404"))
{
Response.Clear();
Response.Redirect(new Uri(Request.Url.ToString()).GetLeftPart(UriPartial.Authority) + ApplicationConfig.Instance.PrefixLang + "/404");
}
else if (statusCode >= 500 && statusCode < 600 && Request.Path != (ApplicationConfig.Instance.PrefixLang + "/404") &&
Request.Path.ToLower().IndexOf("sitefinity") == -1)
{
Response.Clear();
Response.Redirect(new Uri(Request.Url.ToString()).GetLeftPart(UriPartial.Authority) + ApplicationConfig.Instance.PrefixLang + "/404");
}
下面的 web.config 配置对我来说很好用:
<authentication mode="None" />
<customErrors mode="RemoteOnly" >
<error statusCode="404" redirect="~/error-pages/404" />
</customErrors>
...
<httpErrors errorMode="Custom">
<clear />
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" path="/error-pages/404" responseMode="ExecuteURL" />
</httpErrors>
在我尝试将 webconfig 更改为 Sitefinity 论坛中的示例之后,我遇到了关于 404 页面的 Sitefinity 问题,但它不起作用。对我有什么想法吗?
我想你不能在网络配置中设置它,我试过并找到了另一种解决方案。所以请检查下面的代码并将其放入您的 globar.asax
int statusCode = Context.Response.StatusCode;
if ((Context.Response.StatusCode == 404 || Context.Response.StatusCode == 400) && Request.Path != (ApplicationConfig.Instance.PrefixLang + "/404"))
{
Response.Clear();
Response.Redirect(new Uri(Request.Url.ToString()).GetLeftPart(UriPartial.Authority) + ApplicationConfig.Instance.PrefixLang + "/404");
}
else if (statusCode >= 500 && statusCode < 600 && Request.Path != (ApplicationConfig.Instance.PrefixLang + "/404") &&
Request.Path.ToLower().IndexOf("sitefinity") == -1)
{
Response.Clear();
Response.Redirect(new Uri(Request.Url.ToString()).GetLeftPart(UriPartial.Authority) + ApplicationConfig.Instance.PrefixLang + "/404");
}
下面的 web.config 配置对我来说很好用:
<authentication mode="None" />
<customErrors mode="RemoteOnly" >
<error statusCode="404" redirect="~/error-pages/404" />
</customErrors>
...
<httpErrors errorMode="Custom">
<clear />
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" path="/error-pages/404" responseMode="ExecuteURL" />
</httpErrors>