Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I had make an reverse proxy using IHttpAsyncHandler class that listen on the iis request and according to the incoming url path i send a request to another site

C#
 public class ReverseProxy : IHttpAsyncHandler
{

    public bool IsReusable
    {
        get
        {
            return true;
        }
    }

    public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, object extraData)
    {
        _context = context;

       //some code
        remoteUrl = GetRemoteUrl(context, ref remoteUrl);

        _request = (HttpWebRequest)WebRequest.Create(remoteUrl);
        _helper.CopyHeadersRequest(context.Request, _request, ref  _newUri);
        // Copy POST Data
        if (context.Request.RequestType == "POST")
        {
            _request.ContentLength = context.Request.ContentLength;
            _request.ContentType = "application/x-www-form-urlencoded";
            _helper.CopyStream(context.Request.InputStream, _request.GetRequestStream());
        }

        return _request.BeginGetResponse(cb, extraData);
    }

    private string GetRemoteUrl(HttpContext context, ref string remoteUrl)
    {
       //get the new site url
    }

    public void EndProcessRequest(IAsyncResult result)
    {
        HttpWebResponse response;
        try
        {

            response = (HttpWebResponse)_request.EndGetResponse(result);

            _helper.CopyHeadersResponce(response, _context, ref  _segments);

         //some other code
        }
        catch (System.Net.WebException we)
        {
            Return404(_context);
            return;
        }
    }

the problem is when i call an remote asp website the response come back without the session cookies (ASP.NET_SessionId). and this remote website lose the session data. What can be the problem ?
Posted
Comments
Rene Bustos 29-Dec-14 13:01pm    
Hi.
How do you pass the HttpContext to the BeginProcessRequest method? have you create a constructor of this?
Best regards.
Member 11303078 30-Dec-14 5:43am    
Hi, the the function BeginProcessRequest is called when an request is coming to the site because the class inherit IHttpAsyncHandler so the context is send by the IIS.
Sincerely

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900