Domanda

Ho personalizzato IHTTPModule per reindirizzare gli utenti alla mia pagina 404 ASPX.

Questo esempio è stato trovato da qualche parte in Internet e questa parte sembra funzionare bene, ma oggi gli amministratori segnalano il prossimo problema:

ciao È stato visto su questo oggi e ho scoperto.Si scopre che è il modulo HTTP "Pagenotfound" che si trobile per WebDav durante il salvataggio dai documenti dell'ufficio.Aggiunge un reindirizzamento HTTP 302 quando memorizzare i documenti.Ciò accade solo se il documento non esiste, funziona bene se si salva su un documento esistente.Può essere testato per rimuovere / aggiungere "Pagenotfoundhtpmodule" da Web.config WebDav funziona bene.

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

Ho controllato i registri e vedo la prossima eccezione:

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

Ma io non so davvero cosa va bene in questo thread e perché è abortito.Qualche idea?

È stato utile?

Soluzione 2

Dovremmo controllare che httpmethod non sia profondo.E solo quindi utilizzare Reindirizzamento.

app.request.httpmethod!="propfind"

Altri suggerimenti

Questo è il comportamento naturale di httpContext

Quando si tenta di reindirizzare la pagina, la filettatura corrente verrà interrotta e il sistema avrà un'eccezione.

Se non si desidera interrompere il thread, passare il metodo di reindirizzamento falso.

risposta.redirect (messaggio, falso);

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top