当前位置:编程学习 > asp >>

asp.net ajax跨二级域代理页面

[csharp]
/// <summary> 
    /// Ajax跨二级域代理页面 
    /// </summary> 
    public class AjaxCrossDomainProxy : IHttpHandler 
    { 
        public void ProcessRequest(HttpContext context) 
        { 
            context.Response.Cache.SetNoStore(); //不需要客户端缓存 
            context.Response.ContentType = "text/plain"; 
            String url = context.Request["url"]; 
             
            HttpWebResponse response = null; 
            Stream stream = null; 
            try   www.zzzyk.com
            { 
                var request = (HttpWebRequest) WebRequest.Create(url); 
                request.Headers.Add("Cookie", context.Request.Headers["Cookie"]); //将当前二级域名的cookie传送过去 
                response = (HttpWebResponse) request.GetResponse(); 
                stream = response.GetResponseStream(); 
                var reader = new StreamReader(stream); 
                String result = reader.ReadToEnd(); 
                context.Response.Write(result); 
            } 
            finally 
            { 
                if(response != null) response.Close(); 
                if(stream != null) stream.Dispose(); 
            } 
        } 
 
        public bool IsReusable 
        { 
            get 
            { 
                return false; 
            } 
        } 
    } 
补充:Web开发 , ASP.Net ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,