Solved

Accessing Request.ServerVariables in a VB file

Posted on 2003-11-10
5
2,409 Views
Last Modified: 2012-08-13
I am developing an ASP.NET Web Application and I have a .vb file that I working with. Within this .vb file I would like to be able to say:

Request.ServerVariables("SERVER_NAME")
Request.ServerVariables("PATH_INFO")

However, it seems that I am unable to access the "Request" object. Is there a way around this in a .vb file?

dtrick
0
Comment
Question by:dtrick
  • 2
  • 2
5 Comments
 
LVL 4

Assisted Solution

by:AdsB
AdsB earned 20 total points
ID: 9718887
Easiest way is as follows:-

in your .vb file you have a procedure...

Public Sub ProcName(ByVal CallingPage as Page)
   Dim servername as string

   servername = CallingPage.Request.ServerVariables("SERVER_NAME")
End Sub

Hope this helps,


AdsB
0
 

Expert Comment

by:theDIV
ID: 9721532
Hi dtrick

all you should need to do is use the httpcontext class as follows:

context.Request.ServerVariables("SERVER_NAME")
context.Request.ServerVariables("PATH_INFO")
0
 

Author Comment

by:dtrick
ID: 9724704
AdsB
How would you call this funtion? More specifically what does the parameter list look like?

theDIV
Is there a class library that I need to import? I tried to import "System.Web.HttpContext", but it didn't work.

Thanks,
dtrick
0
 

Accepted Solution

by:
theDIV earned 30 total points
ID: 9729729
dtrick,

I was using a class in my VB file which inherited from System.Web.UI.Page, making the context class directly available to me.  

If this isnt applicable to you, you can just dim a new httpcontext object, so your code would look like:

Dim context As HttpContext
context.Request.ServerVariables("SERVER_NAME")
context.Request.ServerVariables("PATH_INFO")
0
 

Author Comment

by:dtrick
ID: 9732588
Tried both.... and they work. Thanks a million!
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

776 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