By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,930 Members | 1,383 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,930 IT Pros & Developers. It's quick & easy.

Best way to do local testing?

P: n/a
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
Nov 18 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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" <ja****@magicalia.com> wrote in message
news:uM**************@TK2MSFTNGP15.phx.gbl...
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

Nov 18 '05 #2

P: n/a
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" <ja****@magicalia.com> wrote in message
news:uM**************@TK2MSFTNGP15.phx.gbl...
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

Nov 18 '05 #3

P: n/a
Thanks Kevin that's what I was looking for

"Kevin Spencer" <ks******@takempis.com> wrote in message
news:uU**************@TK2MSFTNGP15.phx.gbl...
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" <ja****@magicalia.com> wrote in message
news:uM**************@TK2MSFTNGP15.phx.gbl...
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


Nov 18 '05 #4

P: n/a

"Janaka" <ja****@magicalia.com> wrote in message news:uM**************@TK2MSFTNGP15.phx.gbl...
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
Nov 18 '05 #5

P: n/a
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" <ja****@magicalia.com> сообщил/сообщила в новостях следующее:
news:uM**************@TK2MSFTNGP15.phx.gbl...
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

Nov 18 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.