ASP.Net – How To’s

How to implement CAS authentication in ASP.NET

CAS is the Central Authentication Service offered by the Identity and Access Management team within Purdue System Security (PSS). Unlike web server assisted authentication and authorization, it requires active application code in the web site to protect a resource.

Please visit the Purdue CAS Authentication page for how to get started.

How to configure my database connection to work in Dev, QA, and Prod

1. Make sure your web.config file has the following:

<configuration>
    <connectionStrings>
	<add name="dev" connectionString="server=devserver.itap.purdue.edu;database=mydb;uid=myuser;pwd=mydevpw" />
	<add name="qa" connectionString="server=qaserver.itap.purdue.edu;database=mydb;uid=myuser;pwd=myqapw" />
	<add name="prod" connectionString="server=prodserver.itap.purdue.edu;database=mydb;uid=myuser;pwd=myprodpw" />
    </connectionStrings>
</configuration>

2. Make sure the code where you make your DB connection has something similar to the following code:
Please note, this was written in C#

SqlConnection conn = null;
string SQLServer = null;

// Figure out which tier this server is
string webServerTier = Environment.GetEnvironmentVariable("TIER");

try {
	// Connection String to Database
	String connString = ConfigurationManager.ConnectionStrings[webServerTier].ToString();
	conn = new SqlConnection(connString);
	
	// set up my SQL command
	SqlCommand cmd = new SqlCommand("SELECT FName, LName FROM NAMES", conn);
	conn.Open();
	
	// SQL Reader to read the information obtained from the SQL command
	SqlDataReader rdr = cmd.ExecuteReader();
	
	while (rdr.Read() == true) {
		String FName = (string)rdr["FName"];
		String LName = (string)rdr["LName"];
		// do something with the LName and FName variables, etc.
	}
	
	rdr.Close();
	rdr.Dispose();
	conn.Close();
	conn.Dispose();
	conn = null;
	
} catch (Exception ex) {
	ErrorMessage.Text = ex.Message;
	ErrorMessage.Visible = true;
}

How to publish an MVC application to the Shared ASP.NET cluster

The shared ASP.NET cluster does not have the MVC global reference libraries installed, so applications using MVC must include all dependencies. Visual Studio will automatically do this if you use it to publish your site:

  1. Make sure your development site (e.g. \\wdvwebasp03.www.purdue.edu\webroot\{sitename}) is mapped to a drive letter, for example Z:
  2. When ready to publish, right-click the top-level of your project in the solution explorer and select “Publish”
  3. If this is your first time publishing…
    1. Select the Custom option in the Publish wizard
    2. Give the new profile a descriptive name (your choice), such as “{project name} on Dev ASP.NET Server”
    3. Select “File System” as the Publish method
    4. For the target, select the root of your application’s path on the web server from your mapped drive. For example, given the mapping shown above, if Z:\ is mapped to \\wdvwebasp03.www.purdue.edu\webroot\{sitename}, and your application lives at {sitename}/{appname}, select Z:\{appname} here.
  4. Click the Publish button That’s it! Assuming other Visual Studio settings are at their defaults, your application will be published in the development sever with all the files it requires to run. If they’re not being published, right-click your project (like step 2 above), but select “Add Deployable Dependencies” and make sure all required dependencies are checked.