我有自定义ihttpmodule将用户重定向到我的404 aspx页面。

此示例在互联网某处找到,这部分看起来很好,但今天管理员报告下一个问题:

嗨 今天已经看到了这个,发现了。事实证明,它是HTTP模块“PagenotFound”,它在从Office文档中保存时为WebDAV展示它。它添加HTTP 302重定向何时存储文档。只有在未存在文档时才会发生这种情况,如果您在现有文档上保存。可以测试以从web.config webdav删除/添加“pagenotfoundhttpmodule”工作正常。

 void ApplicationPreSendRequestContent(object sender, EventArgs e)
        {
            HttpResponse response = app.Response;
            string requestedUrl = app.Request.Url.AbsolutePath;

            if (string.IsNullOrEmpty(requestedUrl))
            {
                LoggingService.WriteError("PageNotFoundHttpModule. PreSend request: HttpApplication Request.Url.AbsolutePath is null ");
                return;
            }

            try
            {
                var urlElements = requestedUrl.Split('/');
                if (urlElements.Length > 0)
                {
                    int pageElementIndex = urlElements.Length - 1;
                    string pageName = urlElements[pageElementIndex] as string;

                    if (string.IsNullOrEmpty(pageName))
                    {
                        pageName = string.Empty;
                    }

                    if (response.StatusCode == 404 && response.ContentType.Equals("text/html", StringComparison.CurrentCulture))
                    {
                        var pathLowercase = Constants.PageNotFoundUrl.ToLower().Trim();
                        var message = string.Format("{0}?oldUrl={1}&k={2}", pathLowercase, requestedUrl, pageName);
                        if (!pathLowercase.EndsWith(pageName.ToLower().Trim()))
                        {
                            response.Redirect(message);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LoggingService.WriteError(ex, "PageNotFoundHttpModule. Exception while working");
            }
        }
.

我检查了日志,我看到下一个例外:

    PageNotFoundHttpModule. Exception while working  Thread was being aborted.  
   at System.Threading.Thread.AbortInternal()     
at System.Threading.Thread.Abort(Object stateInfo)     
at System.Web.HttpResponse.End()     
at PageNotFoundHttpModule.ApplicationPreSendRequestContent(Object sender, EventArgs e).
.

但我真的不知道这个帖子的错误是什么,为什么它的中止。任何想法?

有帮助吗?

解决方案 2

我们应该检查httpmethod没有primined。然后只使用重定向。

app.request.httpmethod!=“propfind”

其他提示

这是httpcontext 的自然行为

当您尝试重定向页面时,将中止当前线程,系统将抛出异常。

如果您不希望线程中止,请通过false以重定向方法。

response.redirect(消息,false);

许可以下: CC-BY-SA归因
scroll top