Best way to do local testing?

J

Janaka

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.AppSettings["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
 
K

Kevin Spencer

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.
 
R

Raghavendra T V

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
 
J

Janaka

Thanks Kevin that's what I was looking for

Kevin Spencer said:
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 said:
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.AppSettings["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
 
H

Hans Kesting

Janaka said:
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.AppSettings["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
 
D

Denis Kondratyev

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")%>'><img src='<%#
Beer.HttpUrlBuilder.BuildUrl("img/logo.gif")%>' height="92" width="157"
alt="îÁ ÇÌÁ×ÎÕÀ" hspace="20"></a>
 

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

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top