Request Object Bombs-Out Class File

  • Thread starter Thread starter clintonG
  • Start date Start date
C

clintonG

I'm using the intrinsic Request object wrong and need some help with this
one. I wrote a class file for some XMLTextWriter tasks and in the class file
I want to use a conditional to determine if the application is running on
the host provider's web server or the web server on my local development
machine. Here is my broken code...

string fileOut;
// Run-time: running on host provider's server
if(Request.ServerVariables["LOCAL_ADDR"] == "XXX.XXX.XXX.XX")
fileOut = HttpContext.Current.Server.MapPath("filename.xml");
else
// Design-time: running on local development server
fileOut = HttpContext.Current.Server.MapPath("filename.xml");

What do I need to change or add to the code in this class file to use the
Request object? Thanks for comments...
 
As long as you have access to your statics... Not sure where you are making
your calls from though. That may also be inaccessible or null.

HttpContext.Current.Request
 
Thanks Justin. I was 'using' System.Web but declaring the
HttpContext.Current.Request seems to have stopped the compiler from
complaining.

<%= Clinton Gallagher


Justin Rogers said:
As long as you have access to your statics... Not sure where you are making
your calls from though. That may also be inaccessible or null.

HttpContext.Current.Request


--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

clintonG said:
I'm using the intrinsic Request object wrong and need some help with this
one. I wrote a class file for some XMLTextWriter tasks and in the class file
I want to use a conditional to determine if the application is running on
the host provider's web server or the web server on my local development
machine. Here is my broken code...

string fileOut;
// Run-time: running on host provider's server
if(Request.ServerVariables["LOCAL_ADDR"] == "XXX.XXX.XXX.XX")
fileOut = HttpContext.Current.Server.MapPath("filename.xml");
else
// Design-time: running on local development server
fileOut = HttpContext.Current.Server.MapPath("filename.xml");

What do I need to change or add to the code in this class file to use the
Request object? Thanks for comments...

--
<%= Clinton Gallagher, "Twice the Results -- Half the Cost"
Architectural & e-Business Consulting -- Software Development
NET (e-mail address removed)
URL http://www.metromilwaukee.com/clintongallagher/
 
Thanks for comments James. The class file is in the same project. It looks
like Justin's suggestion to declare the use
of HttpContext.Current.Request resolved the problem.

<%= Clinton Gallagher

James Curran said:
I'm gonna guess that you defining a class in an assembly that's outside
your web project. Which is fine, except that VisualStudio doesn't
automatically add the reference to the System.Web for you. You have to do
that yourself.

--
Truth,
James Curran
[erstwhile VC++ MVP]
Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com


clintonG said:
I'm using the intrinsic Request object wrong and need some help with this
one. I wrote a class file for some XMLTextWriter tasks and in the class file
I want to use a conditional to determine if the application is running on
the host provider's web server or the web server on my local development
machine. Here is my broken code...

string fileOut;
// Run-time: running on host provider's server
if(Request.ServerVariables["LOCAL_ADDR"] == "XXX.XXX.XXX.XX")
fileOut = HttpContext.Current.Server.MapPath("filename.xml");
else
// Design-time: running on local development server
fileOut = HttpContext.Current.Server.MapPath("filename.xml");

What do I need to change or add to the code in this class file to use the
Request object? Thanks for comments...

--
<%= Clinton Gallagher, "Twice the Results -- Half the Cost"
Architectural & e-Business Consulting -- Software Development
NET (e-mail address removed)
URL http://www.metromilwaukee.com/clintongallagher/
 
Back
Top