Newbie to C#


B

Bishop

I just started a new asp.net job and all the current source is C#. I'm
experenced with vb.net and have been able to convert C# code when needed.
The problem I'm having is that it looks like the previous developer kept all
the source code on the production web server and made changes when needed.
I want to setup a dev enviroment on my workstation and upload changes after
testing them. The problem I'm running into is there is a namespace defined
in each code behind file that refrences the url of the production url.
After getting stuff running on my computer I realised that although the url
in my browser may have said localhost, it's not recognising changes in code
that I make and not stopping at stop points. (also intellesence isn't
working).

So my questions are:
What is a namespace (in this context)
What kind of steps should I take to set this up to run correctly locally
(with the understanding that I can upload the project to the production
server after testing)?
 
Ad

Advertisements

M

Mythran

Bishop said:
I just started a new asp.net job and all the current source is C#. I'm
experenced with vb.net and have been able to convert C# code when needed.
The problem I'm having is that it looks like the previous developer kept
all the source code on the production web server and made changes when
needed. I want to setup a dev enviroment on my workstation and upload
changes after testing them. The problem I'm running into is there is a
namespace defined in each code behind file that refrences the url of the
production url. After getting stuff running on my computer I realised that
although the url in my browser may have said localhost, it's not
recognising changes in code that I make and not stopping at stop points.
(also intellesence isn't working).

So my questions are:
What is a namespace (in this context)
What kind of steps should I take to set this up to run correctly locally
(with the understanding that I can upload the project to the production
server after testing)?

Can you show some source (including the namespace)?

Mythran
 
B

Bishop

Sure, see below:

using System;
using System.Data;
using System.Data.SqlClient;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace admin.somedomain.net
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class login : Page
{
protected Button btnLogin;
protected TextBox txtPsw;
protected TextBox txtUsername;
protected Label lblStatus;

private SqlConnection myCon = null;
private void Page_Load(object sender, EventArgs e)
{
// Put user code to initialize the page here
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnLogin.Click += new System.EventHandler(this.btnLogin_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void btnLogin_Click(object sender, EventArgs e)
{
myCon = new SqlConnection(Global.ConnectionString);
string QueryString = @"SELECT login, password, accesslevel FROM
employees" +
" WHERE login = @login AND password = @password";

SqlCommand myCommand = new SqlCommand(QueryString, myCon);
myCommand.CommandType = CommandType.Text;
myCommand.Parameters.Add("@login", txtUsername.Text);
myCommand.Parameters.Add("@password", txtPsw.Text);
SqlDataReader myReader = null;
try
{
myCon.Open();
myReader = myCommand.ExecuteReader();
if(!myReader.Read())
lblStatus.Text = "Error with login";
else if(myReader["password"].ToString().Trim() == txtPsw.Text)
{
Session["login"] = txtUsername.Text;
Session["accesslevel"] = myReader["accesslevel"].ToString();
FormsAuthentication.RedirectFromLoginPage(txtUsername.Text, false);
}
myReader.Close();
}
catch(Exception ex)
{
lblStatus.Text = ex.Message + "\n" + ex.StackTrace;
}
finally
{
myCon.Close();
}
}
}
}
 
S

sloan

In vb.net there is an "auto matic" namespace.

Its under Project Properties. Its one of thing quirks with VB that I hate.


It has nothing to do with the server or production. Its just a way to
organize files.

You need the SOURCE code...once you rebuild all the dll's and aspx page
locally, you can deploy them.

That's the short explanation. You just need more experience with namespaces
in C#, which does NOT do the "automatic" namespacing that vb does.

C# is a better system...you'll probably agree after you get over the
learning curve.




Bishop said:
Sure, see below:

using System;
using System.Data;
using System.Data.SqlClient;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace admin.somedomain.net
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class login : Page
{
protected Button btnLogin;
protected TextBox txtPsw;
protected TextBox txtUsername;
protected Label lblStatus;

private SqlConnection myCon = null;
private void Page_Load(object sender, EventArgs e)
{
// Put user code to initialize the page here
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnLogin.Click += new System.EventHandler(this.btnLogin_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void btnLogin_Click(object sender, EventArgs e)
{
myCon = new SqlConnection(Global.ConnectionString);
string QueryString = @"SELECT login, password, accesslevel FROM
employees" +
" WHERE login = @login AND password = @password";

SqlCommand myCommand = new SqlCommand(QueryString, myCon);
myCommand.CommandType = CommandType.Text;
myCommand.Parameters.Add("@login", txtUsername.Text);
myCommand.Parameters.Add("@password", txtPsw.Text);
SqlDataReader myReader = null;
try
{
myCon.Open();
myReader = myCommand.ExecuteReader();
if(!myReader.Read())
lblStatus.Text = "Error with login";
else if(myReader["password"].ToString().Trim() == txtPsw.Text)
{
Session["login"] = txtUsername.Text;
Session["accesslevel"] = myReader["accesslevel"].ToString();
FormsAuthentication.RedirectFromLoginPage(txtUsername.Text, false);
}
myReader.Close();
}
catch(Exception ex)
{
lblStatus.Text = ex.Message + "\n" + ex.StackTrace;
}
finally
{
myCon.Close();
}
}
}
}










Mythran said:
Can you show some source (including the namespace)?

Mythran
 
Ad

Advertisements

M

Mythran

Bishop said:
Sure, see below:

using System;
using System.Data;
using System.Data.SqlClient;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace admin.somedomain.net

This namespace is a normal .Net namespace. It has nothing to do with the
website location the web browser is pointing to. Although, the names are
similar, it just is a namespace.


Hmm, from the debugging symptoms, it seems that you may be running in
Release mode. But this doesn't answer why it doesn't recognize the code
changes. You may want to check your Web.config file to see if there is
anything in there that is pointing to the production server, and change it
to point to the local machine. Also make sure that debugging is enabled
(should be if you aren't getting any errors while trying to debug).

HTH,
Mythran
 

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

Top