Pregunta

He personalizado ihttpmodule para redirigir a los usuarios a mi página 404 ASPX.

Este ejemplo se encontró en algún lugar de Internet y esta pieza parece funcionar bien, pero hoy los administradores informan el próximo problema:

hola Se ha visto en esto hoy y se ha encontrado.Resulta que es el módulo HTTP "Pagenotfound" que lo tira para WebDAV al guardarlo de los documentos de la oficina.Agrega una redirección HTTP 302 cuando almacena documentos.Esto sucede solo si el documento no existe, funciona bien si ahorra sobre un documento existente.Se puede probar para eliminar / agregar "Pagenotfoundhttpmodule" de Web.config WebDAV funciona bien.

 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");
            }
        }

No verifiqué registros y veo la siguiente excepción:

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

Pero realmente no sé qué está haciendo mal con este hilo y por qué se abortó.¿Alguna idea?

¿Fue útil?

Solución 2

Debemos verificar que HTTPMethod no se indique.Y solo luego use redireccionamiento.

app.request.httpmethod!="propfind"

Otros consejos

Este es el comportamiento natural de httpcontext

Cuando intenta redirigir la página, se abortará el hilo actual y el sistema lanzará una excepción.

Si no desea que el hilo aborde, pase Falso para redirigir el método.

Response.Redirect (Mensaje, Falso);

Licenciado bajo: CC-BY-SA con atribución
scroll top