Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Best way to do local testing?

Reply
Thread Tools

Best way to do local testing?

 
 
Janaka
Guest
Posts: n/a
 
      08-27-2004
I'm making a web application on my local server which will then be rolled
out onto our live site. My problem is that i tend to have to comment out
and make a few new hard-coded lines in my files to edit changes locally and
then i have to reverse this process to make any changes live. See below
// local myLink.NavigateUrl = "http://localhost/TestSite/Printout.aspx";
myLink.NavigateUrl = http://www.mysite.com/Printout.aspx;

I'm thinking of making a variable in my web.config file to check whether i'm
running the application locally or not. So the following code below will
work:

bool isTest =
Convert.ToBoolean(ConfigurationSettings.AppSetting s["TestSite"]);

if (isTest)
myLink.NavigateUrl = "http://localhost/TestSite/Printout.aspx";
else
myLink.NavigateUrl = http://www.mysite.com/Printout.aspx;

Is there a better method of doing this? Maybe with the Debug class or
something that runs in debugging mode?

Thanks, Janaka


 
Reply With Quote
 
 
 
 
Kevin Spencer
Guest
Posts: n/a
 
      08-27-2004
You can use preprocessor statements to do this:

#if DEBUG
myLink.NavigateUrl = "http://localhost/TestSite/Printout.aspx"
#else
myLink.NavigateUrl = http://www.mysite.com/Printout.aspx;
#endif

The good thing about using preprocessor statements is that the debug code
isn't even compiled into the class when you compile it in Release mode. The
preprocessor statement indicates which line of code should be compiled,
depending upon whether you are compiling in Debug or Release mode.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Janaka" <> wrote in message
news:...
> I'm making a web application on my local server which will then be rolled
> out onto our live site. My problem is that i tend to have to comment out
> and make a few new hard-coded lines in my files to edit changes locally

and
> then i have to reverse this process to make any changes live. See below
> // local myLink.NavigateUrl = "http://localhost/TestSite/Printout.aspx";
> myLink.NavigateUrl = http://www.mysite.com/Printout.aspx;
>
> I'm thinking of making a variable in my web.config file to check whether

i'm
> running the application locally or not. So the following code below will
> work:
>
> bool isTest =
> Convert.ToBoolean(ConfigurationSettings.AppSetting s["TestSite"]);
>
> if (isTest)
> myLink.NavigateUrl = "http://localhost/TestSite/Printout.aspx";
> else
> myLink.NavigateUrl = http://www.mysite.com/Printout.aspx;
>
> Is there a better method of doing this? Maybe with the Debug class or
> something that runs in debugging mode?
>
> Thanks, Janaka
>
>



 
Reply With Quote
 
 
 
 
Raghavendra T V
Guest
Posts: n/a
 
      08-27-2004
Hi Janaka,

Your idea of moving hardcoded values into web.config is good.

But best practises you should never hardcode any values.

if at all you need to hardcode it should be easily configurable as you are
doing in web.config.

Just go ahead. You are on right track.

Thanks
Raghavendra


"Janaka" <> wrote in message
news:...
> I'm making a web application on my local server which will then be rolled
> out onto our live site. My problem is that i tend to have to comment out
> and make a few new hard-coded lines in my files to edit changes locally

and
> then i have to reverse this process to make any changes live. See below
> // local myLink.NavigateUrl = "http://localhost/TestSite/Printout.aspx";
> myLink.NavigateUrl = http://www.mysite.com/Printout.aspx;
>
> I'm thinking of making a variable in my web.config file to check whether

i'm
> running the application locally or not. So the following code below will
> work:
>
> bool isTest =
> Convert.ToBoolean(ConfigurationSettings.AppSetting s["TestSite"]);
>
> if (isTest)
> myLink.NavigateUrl = "http://localhost/TestSite/Printout.aspx";
> else
> myLink.NavigateUrl = http://www.mysite.com/Printout.aspx;
>
> Is there a better method of doing this? Maybe with the Debug class or
> something that runs in debugging mode?
>
> Thanks, Janaka
>
>



 
Reply With Quote
 
Janaka
Guest
Posts: n/a
 
      08-27-2004
Thanks Kevin that's what I was looking for

"Kevin Spencer" <> wrote in message
news:...
> You can use preprocessor statements to do this:
>
> #if DEBUG
> myLink.NavigateUrl = "http://localhost/TestSite/Printout.aspx"
> #else
> myLink.NavigateUrl = http://www.mysite.com/Printout.aspx;
> #endif
>
> The good thing about using preprocessor statements is that the debug code
> isn't even compiled into the class when you compile it in Release mode.

The
> preprocessor statement indicates which line of code should be compiled,
> depending upon whether you are compiling in Debug or Release mode.
>
> --
> HTH,
> Kevin Spencer
> .Net Developer
> Microsoft MVP
> Big things are made up
> of lots of little things.
>
> "Janaka" <> wrote in message
> news:...
> > I'm making a web application on my local server which will then be

rolled
> > out onto our live site. My problem is that i tend to have to comment

out
> > and make a few new hard-coded lines in my files to edit changes locally

> and
> > then i have to reverse this process to make any changes live. See below
> > // local myLink.NavigateUrl =

"http://localhost/TestSite/Printout.aspx";
> > myLink.NavigateUrl = http://www.mysite.com/Printout.aspx;
> >
> > I'm thinking of making a variable in my web.config file to check whether

> i'm
> > running the application locally or not. So the following code below

will
> > work:
> >
> > bool isTest =
> > Convert.ToBoolean(ConfigurationSettings.AppSetting s["TestSite"]);
> >
> > if (isTest)
> > myLink.NavigateUrl = "http://localhost/TestSite/Printout.aspx";
> > else
> > myLink.NavigateUrl = http://www.mysite.com/Printout.aspx;
> >
> > Is there a better method of doing this? Maybe with the Debug class or
> > something that runs in debugging mode?
> >
> > Thanks, Janaka
> >
> >

>
>



 
Reply With Quote
 
Hans Kesting
Guest
Posts: n/a
 
      08-27-2004

"Janaka" <> wrote in message news:...
> I'm making a web application on my local server which will then be rolled
> out onto our live site. My problem is that i tend to have to comment out
> and make a few new hard-coded lines in my files to edit changes locally and
> then i have to reverse this process to make any changes live. See below
> // local myLink.NavigateUrl = "http://localhost/TestSite/Printout.aspx";
> myLink.NavigateUrl = http://www.mysite.com/Printout.aspx;
>
> I'm thinking of making a variable in my web.config file to check whether i'm
> running the application locally or not. So the following code below will
> work:
>
> bool isTest =
> Convert.ToBoolean(ConfigurationSettings.AppSetting s["TestSite"]);
>
> if (isTest)
> myLink.NavigateUrl = "http://localhost/TestSite/Printout.aspx";
> else
> myLink.NavigateUrl = http://www.mysite.com/Printout.aspx;
>
> Is there a better method of doing this? Maybe with the Debug class or
> something that runs in debugging mode?
>
> Thanks, Janaka
>
>


Specifically for URL's you could use Request.ApplicationPath to get the start
for your local url.
A second approach is to use the "~" in your URL's, which expands to the
applicationpath, *IF* that URL is processed by asp.net.
You then use myLink.NavigateURL = "~/PrintOut.aspx", which will lead to
the correct file.

Hans Kesting


 
Reply With Quote
 
Denis Kondratyev
Guest
Posts: n/a
 
      08-27-2004
I use HttpUrlBuilder from Rainbow portal (www.rainbowportal.net):


public class HttpUrlBuilder

{

/// <summary>

/// Builds the url for get to current portal home page

/// containing the application path, portal alias, tab ID, and language.

/// </summary>

public static string BuildUrl()

{

return(BuildUrl("~/" + HttpUrlBuilder.DefaultPage, 0, 0, null, string.Empty,
string.Empty,string.Empty));

}

/// <summary>

/// Builds the url for get to current portal home page

/// containing the application path, portal alias, tab ID, and language.

/// </summary>

/// <param name="targetPage">Linked page</param>

public static string BuildUrl(string targetPage)

{

return(BuildUrl(targetPage, 0, 0, null, string.Empty, string.Empty,
string.Empty));

}

...... (many lines of code)



It load site url from web config and create urls. In aspx files I use
HttpUrlBuild too:

<a href='<%# Beer.HttpUrlBuilder.BuildUrl("Default.aspx")%>'><i mg src='<%#
Beer.HttpUrlBuilder.BuildUrl("img/logo.gif")%>' height="92" width="157"
alt="На главную" hspace="20"></a>



"Janaka" <> сообщил/сообщила в новостях следующее:
news:...
> I'm making a web application on my local server which will then be rolled
> out onto our live site. My problem is that i tend to have to comment out
> and make a few new hard-coded lines in my files to edit changes locally

and
> then i have to reverse this process to make any changes live. See below
> // local myLink.NavigateUrl = "http://localhost/TestSite/Printout.aspx";
> myLink.NavigateUrl = http://www.mysite.com/Printout.aspx;
>
> I'm thinking of making a variable in my web.config file to check whether

i'm
> running the application locally or not. So the following code below will
> work:
>
> bool isTest =
> Convert.ToBoolean(ConfigurationSettings.AppSetting s["TestSite"]);
>
> if (isTest)
> myLink.NavigateUrl = "http://localhost/TestSite/Printout.aspx";
> else
> myLink.NavigateUrl = http://www.mysite.com/Printout.aspx;
>
> Is there a better method of doing this? Maybe with the Debug class or
> something that runs in debugging mode?
>
> Thanks, Janaka
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Best way to loop through ArrayList and remove elements on the way? Kevin Java 16 01-30-2008 08:54 PM
way way way OT: MCNGP Announcement Neil MCSE 174 04-17-2006 05:55 PM
Any way/Best way to simulate 3:2 mode on an S2 IS? Joe Digital Photography 0 03-09-2006 05:35 PM
AMD Opteron: 1-way, 2-way, ... Up to 8-way. John John Windows 64bit 12 12-27-2005 08:17 AM
What is the best way to make dual-way xml databinding? Stan ASP .Net 3 05-05-2005 02:07 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57