Is there any way to catch all incoming requests to controllers without using ActionFilter
's before handling requests by asp.net?
Asked
Active
Viewed 1,202 times
0

Saber Amani
- 6,409
- 12
- 53
- 88
-
Something like an ISAPI filter: http://msdn.microsoft.com/en-us/library/ms524610(v=vs.90).aspx – rene Dec 06 '14 at 10:12
-
1I doubt you need an isapi filter, rather you'd want something at asp.net level. http://blogs.msdn.com/b/rodneyviana/archive/2014/02/06/logging-incoming-requests-and-responses-in-an-asp-net-or-wcf-application-in-compatibility-mode.aspx http://stackoverflow.com/questions/1038466/logging-raw-http-request-response-in-asp-net-mvc-iis7 – Wiktor Zychla Dec 06 '14 at 10:28
-
@WiktorZychla thanks for your reply, Thats what I want, IHttpModule. – Saber Amani Dec 06 '14 at 10:33
1 Answers
-1
in your Startup.cs
file place this code into the Configure()
method:
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseMvc();
//your code below
app.Run(async (context) =>
{
string body;
using (Stream receiveStream = context.Request.Body)
{
using (StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8))
{
body = readStream.ReadToEnd();
}
}
Console.WriteLine(body.ToString());
});
}
then pls note the app.UseMvc()
always has a priority, meaning any route specified in your app goes to the controller only. so either specify another route, or dont work with routes in your MVC but instead place your routing into the interception within app.Run(async (context)

ulkas
- 5,748
- 5
- 33
- 47