Best way to do local testing?

Discussion in 'ASP .Net' started by Janaka, Aug 27, 2004.

  1. Janaka

    Janaka Guest

    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
    Janaka, Aug 27, 2004
    #1
    1. Advertising

  2. 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.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
    >
    >
    Kevin Spencer, Aug 27, 2004
    #2
    1. Advertising

  3. 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.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
    >
    >
    Raghavendra T V, Aug 27, 2004
    #3
  4. Janaka

    Janaka Guest

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

    >
    >
    Janaka, Aug 27, 2004
    #4
  5. Janaka

    Hans Kesting Guest

    "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.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
    Hans Kesting, Aug 27, 2004
    #5
  6. 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>



    "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.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
    >
    >
    Denis Kondratyev, Aug 27, 2004
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hari Sekhon
    Replies:
    4
    Views:
    276
    Rob Wolfe
    Sep 11, 2006
  2. Tim Golden
    Replies:
    2
    Views:
    247
  3. Tim Golden
    Replies:
    3
    Views:
    257
  4. Diego Martins
    Replies:
    5
    Views:
    5,246
    Diego Martins
    Jun 19, 2007
  5. still just me

    Testing File Existence - best way?

    still just me, Dec 13, 2007, in forum: Perl Misc
    Replies:
    2
    Views:
    102
    Juha Laiho
    Dec 27, 2007
Loading...

Share This Page