enfekted
July 24th, 2005, 11:39 AM
What is the best way to send information from an IHttpModule I developed to a loaded Page that I won't be developing.
Essentially, I need some sort of reporting to the page to let it know what happened in the IHttpModule. I attempted to URLEncode a serialized class and add it to the headers, but at this point the headers are read only.
Any one know the best way to do this?
This is how I'm attempting to do it now (it doesn't work).
[SerializableAttribute()]
public class TransferInfo
{
/* Reporting info goes here... */
public const string TransferInfoHeaderName = "SA_TRANSFER_INFO";
private TransferInfo()
{
}
/* This method is called in the Page to get the results */
public static TransferInfo GetTransferResults( HttpRequest Request )
{
if ( Request == null ) return new TransferInfo();
string urlEncoded = Request.Headers[TransferInfoHeaderName] as string;
if ( urlEncoded == null ) return new TransferInfo();
byte[] buffer = HttpUtility.UrlDecodeToBytes( urlEncoded );
MemoryStream stream = new MemoryStream( buffer );
BinaryFormatter bf = new BinaryFormatter();
return bf.Deserialize( stream ) as TransferInfo;
}
/* This method is called in the IHttpModule to store the results */
public static void WriteToHeader( TransferInfo info, HttpRequest Request )
{
BinaryFormatter bf = new BinaryFormatter();
MemoryStream stream = new MemoryStream();
bf.Serialize( stream, info );
string urlEncoded = HttpUtility.UrlEncode( stream.ToArray() );
Request.Headers.Add( TransferInfoHeaderName, urlEncoded );
}
/* Other stuff goes here */
}
Essentially, I need some sort of reporting to the page to let it know what happened in the IHttpModule. I attempted to URLEncode a serialized class and add it to the headers, but at this point the headers are read only.
Any one know the best way to do this?
This is how I'm attempting to do it now (it doesn't work).
[SerializableAttribute()]
public class TransferInfo
{
/* Reporting info goes here... */
public const string TransferInfoHeaderName = "SA_TRANSFER_INFO";
private TransferInfo()
{
}
/* This method is called in the Page to get the results */
public static TransferInfo GetTransferResults( HttpRequest Request )
{
if ( Request == null ) return new TransferInfo();
string urlEncoded = Request.Headers[TransferInfoHeaderName] as string;
if ( urlEncoded == null ) return new TransferInfo();
byte[] buffer = HttpUtility.UrlDecodeToBytes( urlEncoded );
MemoryStream stream = new MemoryStream( buffer );
BinaryFormatter bf = new BinaryFormatter();
return bf.Deserialize( stream ) as TransferInfo;
}
/* This method is called in the IHttpModule to store the results */
public static void WriteToHeader( TransferInfo info, HttpRequest Request )
{
BinaryFormatter bf = new BinaryFormatter();
MemoryStream stream = new MemoryStream();
bf.Serialize( stream, info );
string urlEncoded = HttpUtility.UrlEncode( stream.ToArray() );
Request.Headers.Add( TransferInfoHeaderName, urlEncoded );
}
/* Other stuff goes here */
}