Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > changing Request.InputStream

Reply
Thread Tools

changing Request.InputStream

 
 
karahan celikel
Guest
Posts: n/a
 
      03-02-2004
Is there a way to modify the request stream?

I tried to do it using Request.Filter, but no success so far.

Thanks.

Karahan Celikel


 
Reply With Quote
 
 
 
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      03-03-2004
Hi Karahan,

Thanks for posting in the community!
From your description, you're wanting to do some certain modification on
the Request's InputStream and also you found using the Request Filter
HttpModule not worked, yes?
If there is anything I misunderstood, please feel free to let me know.

Based on my experience, generally if we'd like to do some general
operations on the Request's InputStream, the only way is just the Filter
httpMoudle. But this way may be somewhat complex because that means we need
to directly deal with the raw byte stream of the Request. Here are some
tech articles on using the HTTPMODULE to generate Fitler:


#Intercepting Filter
http://msdn.microsoft.com/library/en...erceptingFilte
r.asp?frame=true

#Implementing Intercepting Filter in ASP.NET Using HTTP Module
http://msdn.microsoft.com/library/en...erceptingFilte
rInASP.asp?frame=true

#Filtering HTTP Requests with .NET
http://www.ondotnet.com/pub/a/dotnet...ttpfilter.html

#HttpRequest.Filter Property
http://msdn.microsoft.com/library/en...WebHttpRequest
ClassFilterTopic.asp?frame=true

#Build an ASP.NET HttpRequest Log Filter
http://www.eggheadcafe.com/articles/20030813.asp

In addition, since you mentioned that you failed to get it work, would you
please provide some further infos on your code logics or what kind of
detailed problems you met? Thanks.


Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

 
Reply With Quote
 
 
 
 
Karahan Celikel
Guest
Posts: n/a
 
      03-03-2004
Hi Steven,

I have an HttpModule and I hook into Application's BeginRequest event here

************************************************** *****************

private void BeginRequest(object sender, EventArgs e)
{
HttpApplication app = (HttpApplication)sender;
app.Context.Request.Filter = new
MyRequestFilter(app.Context.Request.Filter);
}
************************************************** *****************

MyRequest filter is a subclass of Stream. Following is that class. I won't
show the other stream overrides for the sake of readibility.

************************************************** *****************

public class MyRequestFilter:Stream
{
private Stream _sink;
public MyRequestFilter(Stream sink)
{
_sink = sink;
}

public override int Read(byte[] buffer, int offset, int count)
{
int c = _sink.Read(buffer, offset, count);
Here I want to change the buffer
return c;
}

************************************************** *****************

In the Read method I have a buffer array representing the request string. I
can change the values in it but obviously I can't resize it.

I want to find the occurances of string X and replace it with string Y in
the request stream without any size limitations.

Thanks


 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      03-04-2004
Hi Karahan,

Thanks for your response. Yes, as you've found that the Filter HttpModule
can help modifing the Request's inputstream. However, this modification is
very constrained that we can only do simple replacement but not change the
stream's size. Also, do you think it possbile that we implement your former
requirement via other means rather than modifying the input stream? Any
way, I'll consult some further experts to see whether there are any other
ideas.


Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

 
Reply With Quote
 
Karahan Celikel
Guest
Posts: n/a
 
      03-04-2004
Hi Steven,

Actually Request.InputStream is readonly. As far as I understand it is the
Filter that can be writable. If there is a filter of the request then
Application uses this filter instead of Request.InputStream.
Yesterday , I found a workaround to the problem. But it is not an elegant
solution.

Before the following Read method of the filter is called

public override int Read(byte[] buffer, int offset, int count)
{
int c = _sink.Read(buffer, offset, count);
Here I want to change the buffer
return c;
}

size of the buffer array and count parameters are determined by the the
Length property of the Filter itself. So we can deceive the caller here by
manipulating the Length property. Here we can generate the new request
string and return the length of it

public override long Length
{
get
{
if(this.newRequestStr!="")
return this.newRequestStr.Length;
else
{
if(_sink.Length!=0)
{
this.newRequestStr = ProcessRequest();
return this.newRequestStr.Length;
}
else
return 0;
}
}
}

and we need to change the Read method

public override int Read(byte[] buffer, int offset, int count)
{
byte[] newBuffer =
System.Text.Encoding.UTF8.GetBytes(this.newRequest Str);

for(int i=0;i<count;i++)
buffer[i] = newBuffer[i];

return newRequestStr.Length;
}


But as you can see, generating the new request string in the getter of the
Length property is something like a hack rather than an elegant solution.

I would appreciate if you can investigate it further. There is not much
documentation about this topic.

Thanks

Karahan Celikel


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing style of the numbers in a CSS <ol> without changing the style of the <li> Aaron Beall HTML 2 09-14-2007 08:07 PM
<FAQENTRY>I'm changing my page but nothing is changing on the screen. Why?</FAQENTRY> VK Javascript 3 03-15-2007 04:59 PM
Guide: Changing your Power Supply fan RObErT_RaTh Reviews & How-To's 0 08-24-2005 04:05 PM
changing file extension without changing filename jamy Computer Support 4 03-04-2005 01:03 AM
Difficulty in changing the Connection Server control path changing ... Samridhi Kumar Shukla ASP .Net 1 11-30-2003 02:31 AM



Advertisments