How to modify servervariables?

S

Sanjib Biswas

Hi,

I have an ASP.Net application which talks to an ASP application. As the
ASP.Net application talk to the ASP application, the REMOTE_ADDR server
variable points to the IP address of the ASP.Net application. I would like
to modify server variables to point to the actual client IP address rather
than ASP.Net application.

Client -> ASP.Net (Web application) -> ASP (Web application)

Request.ServerVariables["REMOTE_ADDR"] = clientIP;

Above code is throwing an exception.

[PlatformNotSupportedException: Operation is not supported on this
platform.]
System.Web.HttpServerVarsCollection.Set(String name, String value)
+3254625
System.Collections.Specialized.NameValueCollection.set_Item(String name,
String value) +9

I have also tried

Request.ServerVariables.Remove("remote_addr");
Request.ServerVariables.Add("REMOTE_ADDR", clientIP);

This code throws "Cannot directly modify server variables". Any idea how to
tackle this problem?

Thanks,
Sanjib
 
A

Alexey Smirnov

Hi,

   I have an ASP.Net application which talks to an ASP application. Asthe
ASP.Net application talk to the ASP application, the REMOTE_ADDR server
variable points to the IP address of the ASP.Net application. I would like
to modify server variables to point to the actual client IP address rather
than ASP.Net application.

Client -> ASP.Net (Web application) -> ASP (Web application)

Request.ServerVariables["REMOTE_ADDR"] = clientIP;

First of all, I think you logic is wrong here. I guess, you get the
"incorrect" IP on the ASP side and not in the ASP.NET application,
where Request.ServerVariables["REMOTE_ADDR"] is already equal to
clientIP and

Request.ServerVariables["REMOTE_ADDR"] = clientIP;

makes no sense to me. Maybe you should try to pass this ip via
querystring to ASP. For example,

Client requests "default.aspx"
->
ASP.Net (Web application) takes an IP and call "default.asp?from_ip="
+ IP
->
ASP (Web application) takes the IP from the "from_ip" value

Regarding HttpRequest.ServerVariables Property, it's by design
"***gets*** a collection of Web server variables"
http://msdn2.microsoft.com/en-us/library/system.web.httprequest.servervariables(VS.80).aspx

Hope this helps
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top