How to access the HttpContext.Current.Request in C++ .NET Class library

  • Thread starter Thread starter Phil Ten
  • Start date Start date
P

Phil Ten

Hello,

I am working on a .NET C++ project based on the
"Class Library (.NET)" wizard of Visual Studio .NET 2003.

I would like to know if my .NET component is running
in a ASP.NET page (.apsx file), and if it is the case I would
like to execute a specific task based on the current
HTTP request.

I searched the Microsoft documentation but couldn't
find much information.

1) How can I know if my component is running in an
ASP.NET page?

2) If so, how can I access the current HTTP request?

I think that I must access object
"System.Web.HttpContext.Current.Request".
If this is correct, I have no idea how to do so
within my C++ .NET project?

All help would very appreciated. Thank you very much.

Phil Ten
 
Hi.

First, you need to include a reference to System.Net.dll

This line would go into the stdafx.h file:
#include "System.Web.dll"

In you c++ file you would then write

using namespace System::Web;

in your method you would write
HttpContext *context = HttpContet::Current;
if ( context ) // remember to test if it's null
HttpRequest *request = context->Request;
 
Thank you very much Peter. I followed your instructions
and it worked perfectly :)

Phil Ten.
 
Back
Top