PC Review


Reply
Thread Tools Rating: Thread Rating: 1 votes, 5.00 average.

changing Request.InputStream

 
 
karahan celikel
Guest
Posts: n/a
 
      2nd Mar 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
 
      3rd Mar 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
 
      3rd Mar 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
 
      4th Mar 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
 
      4th Mar 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.newRequestStr);

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
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      9th Mar 2004
Hi Karahan,

After further researching and consulting some other experts. Currently it
seems that the Filter is the only way to do some genreic simple
modification. But I did not found any other means on change the In stream's
size. The only thing found is that we can completely modify the Request
Stream via SoapExtension in ASP.NET webservice(soap message). But since it
based on soap request which is quite different from our situation, we still
haven't any better solution.


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
 
      9th Mar 2004
Thanks Steven.

"Steven Cheng[MSFT]" <v-(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Karahan,
>
> After further researching and consulting some other experts. Currently it
> seems that the Filter is the only way to do some genreic simple
> modification. But I did not found any other means on change the In

stream's
> size. The only thing found is that we can completely modify the Request
> Stream via SoapExtension in ASP.NET webservice(soap message). But since it
> based on soap request which is quite different from our situation, we

still
> haven't any better solution.
>
>
> 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
 
New Member
Join Date: Jun 2012
Posts: 1
 
      7th Jun 2012
I think that this is the good point of the community, some questions can live for a long time.
Now, I also have to modify the content of the files is uploaded by the multiple upload functon of SharePoint portal (it is using PUT method).

And this is my issue: the Filter's Read method isn't called. It works great for the asp.net website I created. But doesn't work for SharePoint.

Thank you very much.
Huy
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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
How to stop entire document style changing when changing 1 line? =?Utf-8?B?VHJveSBBLiBDb3VydG5leQ==?= Microsoft Word Document Management 4 1st May 2005 11:10 PM
problem in changing changing color ms Microsoft Outlook 1 30th Jan 2005 08:37 PM
Keeping Calendar times from changing when changing local time zone. George Lob Microsoft Outlook Discussion 1 22nd Nov 2004 06:14 PM
Changing (Part of) Header Without Changing Footer or Rest of Header Paul Cross Microsoft Excel Programming 3 20th May 2004 10:42 PM
changing font sizes without changing cell sizes =?Utf-8?B?c2FtIGxpcG1hbg==?= Microsoft Excel Misc 4 11th May 2004 10:43 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:09 AM.