91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Response.Redirect 原理及實現

發布時間:2020-08-04 11:00:16 來源:網絡 閱讀:938 作者:tongling_zzu 欄目:編程語言

之前一直以為Response.Redirect (“default1.aspx”)的運行原理是這樣的Response.Redirect 原理及實現

但經過斷點測試發現不是,當程序執行到Response.Redirect (“default1.aspx”);時 下邊會跳轉到default1.aspx下的Page_Load()方法中。也就是說2,3根本沒有運行,只有1跟4,瀏覽器在根據4返回的狀態碼來在前臺地址欄顯示出不同的url,說到這里了 咱們就反編譯一把Response.Redirect看看里面的具體實現:

internalvoidRedirect(string url, bool endResponse, bool permanent)
{
    if (url == null)
    {
        thrownewArgumentNullException("url");
    }
    if (url.IndexOf('\n') >= 0)
    {
        thrownewArgumentException(SR.GetString("Cannot_redirect_to_newline"));
    }
    if (this._headersWritten)
    {
        thrownewHttpException(SR.GetString("Cannot_redirect_after_headers_sent"));
    }
    Pagepage = this._context.HandlerasPage;
    if ((page != null) && page.IsCallback)
    {
        thrownewApplicationException(SR.GetString("Redirect_not_allowed_in_callback"));
    }
    url = this.ApplyRedirectQueryStringIfRequired(url);
    url = this.ApplyAppPathModifier(url);
    url = this.ConvertToFullyQualifiedRedirectUrlIfRequired(url);
    url = this.UrlEncodeRedirect(url);
    this.Clear();
    if (((page != null) && page.IsPostBack) && (page.SmartNavigation && (this.Request["__smartNavPostBack"] == "true")))
    {
        this.Write("<BODY><ASP_SMARTNAV_RDIR url=\"");
        this.Write(HttpUtility.HtmlEncode(url));
        this.Write("\"></ASP_SMARTNAV_RDIR>");
        this.Write("</BODY>");
    }
    else
    {
        this.StatusCode = permanent ? 0x12d : 0x12e;
        this.RedirectLocation = url;
        if (UriUtil.IsSafeScheme(url))
        {
            url = HttpUtility.HtmlAttributeEncode(url);
        }
        else
        {
            url = HttpUtility.HtmlAttributeEncode(HttpUtility.UrlEncode(url));
        }
        this.Write("<html><head><title>Object moved</title></head><body>\r\n");
        this.Write("<h3>Object moved to <a href=\"" + url + "\">here</a>.</h3>\r\n");
        this.Write("</body></html>\r\n");
    }
    this._isRequestBeingRedirected = true;
    EventHandlerredirecting = Redirecting;
    if (redirecting != null)
    {
        redirecting(this, EventArgs.Empty);
    }
    if (endResponse)
    {
        this.End();
    }
}

其中由37,38行的

this.StatusCode = permanent ? 0x12d : 0x12e;
this.RedirectLocation = url;

可以看出狀態碼和跳轉地址是在這里賦值的,我邪惡的感覺到擴展IhttpModule可以攔截http狀態碼,使用js代碼段來實現http頁面的跳轉,代碼如下:

using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
namespace ClassLibrary2
{
    public class Class1 : System.Web.IHttpModule
    {
        public void Init(HttpApplication application)
        {
            application.PreSendRequestHeaders += new EventHandler(application_PreSendRequestHeaders);
        }
        private void application_PreSendRequestHeaders(object sender, EventArgs e)
        {
            HttpApplication Application = (HttpApplication) sender;
            HttpContext context = Application.Context;
            if (context.Response.StatusCode == 302)
            {
                context.Response.Write("<script>window.open(’" + context.Response.RedirectLocation + "’)</script>");
                context.Response.StatusCode = 200;
            }
        }
    }
}
  

然后再配置一下web.config

<?xml version="1.0"?>
  <configuration>
  <system.web>
  <compilation debug="true"/>
  <authentication mode="Windows"/>
  <httpModules>
  <add name="MyModule" type="ClassLibrary2.Class1,ClassLibrary2"></add>
  </httpModules>
  </system.web>
  </configuration>


向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

红河县| 宜君县| 内丘县| 瑞丽市| 贵南县| 普洱| 信阳市| 柯坪县| 灵山县| 东兴市| 睢宁县| 岳普湖县| 张家口市| 新和县| 木兰县| 星子县| 遵义市| 高阳县| 邢台市| 卢湾区| 横峰县| 石狮市| 德州市| 邛崃市| 甘肃省| 曲沃县| 前郭尔| 丘北县| 铜鼓县| 潜山县| 繁峙县| 宝兴县| 长汀县| 从江县| 闽侯县| 旬阳县| 嵊泗县| 基隆市| 上杭县| 长沙市| 安西县|