Hind your user name and password

 

In this sample you will play with the first application again, which lists all group names.  However, we will hide the user name and the password from public. Do as the follows:

 

1)      Copy the script in web.config to a file named web.config, and replace the web.config file on your "v2.0" directory. Modify the connectionStrings in the file, so that name=whatever-you-like and initial catalog=your-database-name.

 

2)      Copy the script in aspx to a file named SampleGroupNames.aspx, and copy the script in code to a file named SampleGroupNames.aspx.cs.

 

3)      Modify the connectionString in the file SampleGroupNames.aspx.cs, so that the string myuserid is your-database-name and the index of ConnectionStrings is whatever-you-use-in-step1.

 

4)      Create a subdirectory 7thApp under \\Development\net\home\\your-username\www, and upload the two files SampleGroupNames.aspx and SampleGroupNames.aspx.cs  to \\Development\net\home\your-username\www\7thApp.

 

5)      Open IE browser, try http://www.development.ccs.neu.edu/home/your-username/7thApp/SampleGroupNames.aspx, and you will see all group names are listed in the ListBox.

 

 

Script Explanation

 

web.config

 

1)      <connectionStrings> section adds a new entry to connectionStrings.

 

2)      We can use the new entry in any web applications located under "v2.0" dirctory by referring to ConfigurationManager.ConnectionStrings[name-of-the-entry].

 

3)   "integrated security=True" indicates that the current Windows account credentials will be used for authentication.

  

SampleGroupNames.aspx.cs

 

1)      String myuserid is used to keep your database name.

 

2)      The value of sqlConnection1.ConnectionString comes from the new entry of ConfigurationManager.ConnectionStrings.

 

3)      The SQL command has to specify the name of the database explicitly, because we are not logging in by using the SQL Server account directly.