Solved

Can someone show me how I would pass an HttpRequest object into a class library using VB.NET?

Posted on 2006-07-21
16
322 Views
Last Modified: 2008-02-01
Here is the problem:

I have a class library, and one of the possible inputs into this class library is the System.Web.HttpRequest.  However, once I separated the classes and placed them into a class library (they were initially coded directly into a new website project, which hada access to System.Web.HttpRequest), I no longer have access to this object!

I see there is a System.Net.HttpWebRequest class available though.  Can I use this to accept an object of type System.Web.HttpRequest?  And how would I do this?  Since this seems to be a very advanced .NET question, and I am desperate to move the code to a class library (so I can call the class library from a web service), I am awarding 500 pts to whomever or whoever can show me how to be able to accept the System.Web.HttpRequest object in a class library.

Thanks so much for your help.
0
Comment
Question by:louisiana_blues
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 4
  • 3
16 Comments
 
LVL 24

Expert Comment

by:Justin_W
ID: 17155707
Public Sub foo(r As System.Net.HttpWebRequest)
   'TODO: implement
End Sub
0
 
LVL 24

Expert Comment

by:Justin_W
ID: 17155716
Or if you really meant the System.Web.HttpRequest class:

Public Sub foo(r As System.Web.HttpRequest)
   'TODO: implement
End Sub
0
 

Author Comment

by:louisiana_blues
ID: 17155753
No, sorry, I guess I did not make myself clear.

Here is the scenario.  I have a System.Web.Httprequest object from a Webservice (or a Webpage).  I have a set of class libraries, that do NOT HAVE ACCESS TO System.Web.Httprequest (try to create a new class library and do an Imports System.Web and you will see what I mean).

So my question is, what code do I need to use to be able to cast or do whatever, in order to use an HttpWebRequest object in a class library using VB.NET?  Sure, I can do one or the other above, but that does not help me, since I have an object of type System.Web.HttpRequest, that is passed into a classlibrary, with, as far as I can tell, only a System.Net.HttpWebRequest, which of course, is not the same thing...

Is that any clearer?  And thanks so much for the response.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:louisiana_blues
ID: 17155776
So, using your example, I want to use:

Public Sub foo(r As System.Web.HttpRequest)
   'TODO: implement
End Sub

But from inside a class library...but if you go into VS 2005 (or 2003, I guess) and create a new 'Class Library', and type in:

Imports System.Web.  *you will not see HttpRequest as an available object*

Which is the problem I am having!
0
 
LVL 24

Assisted Solution

by:Jeff Certain
Jeff Certain earned 400 total points
ID: 17155795
Strange.

I created a new class library, and added a reference to System.Web.

I was then able to import system.web into my class with no problem at all.

The issue at hand may be that your web site referenced System.Web as part of the project, but your class library doesn't -- so you need to add the reference by hand.
0
 

Author Comment

by:louisiana_blues
ID: 17155822
Yes, of course you can.  But you will not find a class *inside* System.Web called 'HttpRequest'  So if you try to define a variable called:

Dim orequest As HttpRequest

You will get an error.

If you create a new *website* however, and do an Imports System.Web and then define something as:

Dim orequest As HttpReqest

You will not get an error.

And this is the problem.
0
 

Author Comment

by:louisiana_blues
ID: 17155830
So, if you read my first sentence of the scenario now:

"I have a set of class libraries, that do NOT HAVE ACCESS TO System.Web.Httprequest (try to create a new class library and do an Imports System.Web and you will see what I mean)"

You will understand what I said?
0
 
LVL 24

Accepted Solution

by:
Justin_W earned 100 total points
ID: 17155834
You may need to add an "Assembly Reference" for the System.Web.dll in addition to your Imports statement.

An Imports statement only works for DLLs that are referenced.
0
 
LVL 24

Expert Comment

by:Jeff Certain
ID: 17155845
The approach I outlined worked for me. I was, in fact, able to create a new object of type HttpRequest.

As I stated, I added the System.Web reference to the class library project before importing System.Web.
0
 

Author Comment

by:louisiana_blues
ID: 17155859
Unfortunately, I *do* have a System.Web already in the class library.  I would need something that actually solves this problem of 'how do I access an System.Web.HttpRequest object in a class library?  Since the class library already *has* a System.Web reference, but it doesn't have access to any of the classes I need, how do I actually get at it?  To I have to do some conversion from a file stream or something?  And even if I do have a file stream, how do I then convert that back to an HttpRequest object?
0
 

Author Comment

by:louisiana_blues
ID: 17155862
Can you give me specific instructions on what you did?
0
 

Author Comment

by:louisiana_blues
ID: 17155881
Aha. Yes!  I see.  Darn, but I should know that.  Thank you both for your help.  Now, since you both helped in answering my question, you shall have to share again, Chaosian. :)

Thanks you both for your help!
0
 

Author Comment

by:louisiana_blues
ID: 17155891
Hmm.  Well, I tried to give the accepted answer to Chaosian, but somehow, it did not work right.  Sorry Chaosian...I did give you the balance of the points though...
0
 
LVL 24

Expert Comment

by:Jeff Certain
ID: 17155904
LOL... no problem. Glad it's working!

Sometimes those references can be tricky. Since everything references System by default, System.Web shows up even if you don't have a reference to it... but none of the System.Web classes are available.

Seems like Microsoft could have made the process a little simpler.
0
 

Author Comment

by:louisiana_blues
ID: 17155914
Thank you Chaosian.  Could you help me with my other 500 pt question?  The problem I have reading and updating the appconfig file?  You definitely are an expert!
0
 
LVL 24

Expert Comment

by:Jeff Certain
ID: 17155989
I'll see what I can do :)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question