DOA Training

Get Started. It's Free
or sign up with your email address
Rocket clouds
DOA Training by Mind Map: DOA Training

1. Visual Studio 2010

1.1. Look and feel, views, tabs, dialogs, etc

1.1.1. Does a lot (why the UI sucks)

1.1.2. But you can make it like you want it

1.2. Solution

1.2.1. (Contains projects)

1.3. Projects

1.3.1. Set one as StartUp Project

1.3.2. Starting a new project? see ->

1.4. StartUp Project

1.4.1. Set a "Specific Page" as Start Action

1.5. Debugging

1.5.1. "Go" (green arrow) Saves all files Builds solution Starts debugging the Startup project (and page)

1.5.2. Lectures on Visual Studio debugging

1.6. Clean/Rebuild

1.6.1. If things are wonky and not updating properly

1.6.2. Clean removes all compiled output files (leaving source files)

1.6.3. Rebuild does that AND then builds solution.

2. TFS (Team Foundation Server)

2.1. Create a Team Project

2.2. Work Items

2.2.1. Lectures

2.2.2. Create, don't forget to assign to a user

2.2.3. There is NO search

2.2.4. Work Item Queries (all, mine)

2.3. Using Version Control

2.3.1. Navigating How to Connect to TFS View Source Control View->Team Explorer Double Click "Source Control" View Local project files View -> Solution Explorer

2.3.2. Concepts Revision history! Mapping to a Local Workspace

2.3.3. If you are starting a new Project Workspace dropdown -> "Workspaces ..." -> Add Choose a Local Path Create a "DEV" branch Right click the Team Project Create a folder "DEV" Check in Right click "DEV" folder Branching -> Convert to branch File -> New Project ASP.NET Web Application Target correct framework version Name the solution Check "Add to Source Control" Choose the "DEV" branch as where to store it in source control Choose the local workspace you created above Now you have a Solution, a default project, and a ton of automatically generated files Missing files? Don't forget to check in your files to source control!

2.3.4. Importing an Existing Project that is NOT in TFS yet Connect to TFS Add a new Workspace and map it to a path on your C:\ drive Source control Workspaces Add Configure Next, browse for and select (or make a new) local folder. This is where the workspace will "live" on this machine Make a folder to store your work in source control add Import project files Explore Go into new sub-folder in explorer Put the project files into this directory Add new stuff to source control Select Select any LIB items that are excluded, and then click "Include items" Click Finish Bind the solution to source control Find the solution in the source control explorer window, and open it Bind select and bind, then click OK Now in Solution explorer you should have the solution open Make sure it builds and runs ok Check in!

2.3.5. Working on an Existing Project already in TFS Get the Source Code Double click on the Solution (.sln) file to open

2.3.6. Adding files to Source Control If you are adding libraries or files to the project, you need to figure out what files "should" be in source control In general, you do NOT add /obj: This folder contains intermediate files used during compilation /bin: This folder contains output files generated from the compilation In general, you DO add: Folders containing source files (aspx, vb, etc) /lib folders and the binary files they contain

2.3.7. Daily routine Team Explorer Double-click "Source Control" Right-click project -> Get Specific Version Make code additions, changes, etc. If you add a file, select "Add to source control" checkbox! When you edit a file, it should automatically become checked out and show up in pending changes If you lose connection to TFS, you will see: View -> Other Windows -> Pending Changes Get a list of your Work Items You can associate work items with your changes when you check in Make sure the Workspace here is the same as the one in Source Control Explorer Check in


3.1. "Sites" vs "Apps", what is the difference? (We tend to make Apps)

3.2. Page Structure

3.2.1. Master Page This is the template for the site It holds the HTML structure and content that is *common* across all pages <html> <head> <body> How does one Master display different contents for different pages? asp:ContentPlaceholder Its code-behind VB file can contain Init code that must always run, and utility functions pages may want to call (see BAA Site.Master) Beware "Page Title" weirdness has some odd handling of page titles What you put into the <title> tag in your master page will be overwritten By what's in the aspx page Title attribute at the top or the .Title property in the page's codebehind AND... if you omit the title tag from the master page, an EMPTY one will be added (uselessly) See discussions on this page for more info

3.2.2. Pages Files with .aspx extension These are the pages of your site One page is more or less a "screen" Code behind Server-side VB code that is unique to this page will go in the "code behind" VB file. Note the *similar* name, but followed by .vb Each content page refers to its master _ Notice there are no template/outer HTML tags Has asp:Content items Each Content item has a ContentPlaceHolderID This matches a placeholder in Master To add a page... To add a page

3.2.3. Web User controls Idea: A re-useable chunk of UI and code Something modular Something you want on some pages, but not others Like a navigation control, or a calendar picker Easier than making multiple Master pages Easier than copy/pasting content between pages Will be added to one or more content pages .ascx files To make a new control... ... MSDN uberpage Adding a user control to Master, or to a page Method 1 Method 2

3.3. Page Elements

3.3.1. Overviews PluralSight lecture MSDN W3Schools (a bit dated; easier to read)

3.3.2. HTML tags The fundamental language of web browsers Code in the ASPX page that is passed AS-IS to the browser <tags> that do not have any <namespace:...> prefix And they do not have any "runat=server" attribute <a>, <p>, <div>, <span>, <h1>, etc. COMMENT OUT with <!-- stuff here -->

3.3.3. Server controls Code in the ASPX page that is run on the server There are two types Overview of both HTML Server Controls, Web Server Controls COMMENT OUT with <%-- stuff here --%>

3.3.4. User controls

3.3.5. CSS Lecture series A great resource link "Cascading Style Sheets" Information for the browser about how the site should be rendered (colors, sizes, positions, hiding/showing of certain elements) Parsed by the web browser only (no server side scripting, VB code, etc.) One is created by default, and automatically referenced by the master page .

3.4. Entity Framework

3.4.1. Lectures Create a model from a database Exploring the classes generated from an Entity Data Model Consuming an Entity Model from a separate .NET project LINQ to Entities Updating database items

3.4.2. .EDMX files This is the file type that controls and instructs the generation of VB<-->database code Double clicking the EDMX file in the solution explorer will open up the EDMX editor and also cause the "model browser" view to appear (usually in the same tab area as the Solution explorer)

3.4.3. Notes from class May 7 How things are related We used two types of controls: Web controls (to display or edit data in the browser) Data Source controls (they provide connectivity from Entity objects to the Web controls) They are NOT THE SAME In particular, there was a tendency to click on and code to the data source controls when the intention was to alter properties of the dropdown or grid view The data source control defines the relationship between the Entity objects (which are the code representation of the database), and the Web controls (which allow the browser to display or alter the data) Menus and smart tags For some reason, when MS decided to make wizards for data sources and data-bound controls, they decided to invent an entirely new widget to hide these features under, instead of just piling more crap into the right-click menu or the Properties view, the two other primary places to pile this kind of thing. IMPORTANT: these tags show and hide based on what thing you have currently SELECTED with the mouse (left click) In class this led to a tendency to gravitate toward the nearest visible smart tag, even if it was attached to some control or item OTHER than the one you wanted. I do this too sometimes! If the smart tag doesn't contain the stuff you expect, check your assumptions: are you selected onto the right control? Data binding issues When there are 2 separate projects (Data and Web), you need to copy the connection string into both of them. In the Data project it goes in app.config. In the Web project, it goes in web.config Performing queries in VB code The "it" string But building string queries at run time is dangerous anyway You can use non-dynamic queries expressed in code Anyway, Allie's code (and your own experience) is more with stored procedures

3.4.4. Connecting to a Database and getting a connection string How do you create a connection string property for web.config (etc.)? You can go into Server Explorer, and add a Data Connection Work out the server, instance name, credentials, etc. etc. and click "Test connection" If that works, then save it with "OK" Now look at the Properties window of the connection you just made, and you will see a "Connection String" field. You can copy/paste this guy as needed

3.4.5. "Dynamic Data" auto-generated C.R.U.D. web app Lecture (series) NOTE: this is NOT useable if you are using the "stored proc only" approach to data access You can add these capabilities to an existing project, in the following hacky manner: A Dynamic Data site gives you a ton of "Scaffolding" code, which can then be edited and customized per your needs. What this does, and how it works customization To customize items, you do NOT edit the class in the edmx Designer.vb file, because that will get overwritten each time You use a "partial class". A file containing a class with the same name as the one you want to augment, and the "partial" keyword. Customize data field validation using existing normal-ish attributes Customize using your own logic, by creating NEW completely custom attribute classes that do whatever type of crazy validation you want

3.4.6. GridView magic With a fully enabled Entity Data Source, a Grid View control can do edits and deletes on its own. With "stored procs only", you have to do a bunch more work in the VB. See every BAA list/detail page for example What about *adding* a row? OK, this is non-trivial. There are basically 2 schools of thought Validation (see cross link) In order to do something non-default with the column, go into the column editor and click the "convert to template column" link now in the ASPX you see more verbose code for that column, including an edit controls etc. You can add a validation control and point it at the validation control in order to properly validate the grid view items "My grid view isn't showing any data" Well this can be a number of things, but the one GOTCHA that we ran into in class was that the "AutoGenerateColumns" property was set to "false". Now, you WANT that to be false in most serious cases where you are defining exactly what stuff you want to show and how it should look But if you are simply binding the gridview to some data and want it to magically define its own columns based on whatever is in the data, then set this to true. handy for initial development, debugging, and learning! Recall you can set properties in the Properties view when the control is selected. Also they get written into attributes in the ASPX file, in the control's <asp:...> tag Bound vs. Template fields When you define your own columns, you can use the <asp:BoundField...> sub-tag to describe a field that doesn't require any validation. Anything where you want to customize the way it is rendered, or add validation controls or custom logic for how it works, you will use <asp:TemplateField...> and its child tags If you work hard enough at it (as shown) you can actually get the Design View of your aspx to show you the Template fields of the grid view, so you can graphically edit them. IMO this is not really worth the trouble. Just drag whatever controls you want onto the page somewhere else if you have to, and then cut/paste them in the Source view into the correct template area of the gridview

3.4.7. Validation use the <asp:*Validator> controls, like in the lectures SUPER IMPORTANT: Do not trust or commit any code from the page unless you run the SERVER SIDE VALIDATION TOO (see link) First, you need to call "Validate()" unless the control that posted back has CausesValidation=true If Page.IsValid is false, then you have a validation error. do not commit!. just exit out and let the page load. the validator controls should show up what is wrong to the user Instead of hardcoding the validation limits/expressions in ASPX, you can calculate them in the .vb Page_Load and pass them in <% variables %>. See BAA's use of asp:RangeValidator One cryptic "GOTCHA" error I encountered Invalid postback or callback argument. Event validation is enabled using '<pages enableEventValidation=“true”/>' See link: In my case, this happened because I was indiscriminately filling my GridView in the Page_Load function. But when validation or other non-default loading occurs, the Page_Load function runs again, and the data population logic SHOULDN'T run. So I moved my code somewhere else that would not run except when I really did want to load or change the value in the gridview. Keep in mind Page_Load ALWAYS runs any time this page is requested by the browser: either a GET request, a POST back, or AJAX-y UpdatePanel partial updates etc. etc. Look up ASP.NET "validation group" and "validation summary". You can put all the error messages into one list. Then you can choose to either leave the verbose error in each Validator control as before, or else tell the Validator to just display a red "*" or something short to indicate that this field needs work. The summary will get triggered when the user clicks something that will (otherwise) cause the page to post back Note that we can't (trivially) use the nifty Data Annotation method that works for Dynamic Data auto-CRUD apps, although see:

3.4.8. QueryExtender You have to do some typing in the ASPX file to use this, but you can use the QueryExtender control to do searching or filtering on an EntityDataSource What's the point of doing it here instead of filtering code in the VB? Some people prefer this more "declarative" syntax, where you use ASPX tags to define how things work. It's handy for things that are very mechanical and don't change much based on circumstances, and it keeps you from having to know much about the VB code behind. I leave out more details here, because you guys intimated that you will probably always be using stored procs for data access, which alas, makes a large portion of the cool things you can do with EF and ASP.NET data objects moot

3.4.9. Switching an EDMX file to a completely different database Let's say you selected the wrong database, or you have a test shell/sandbox project and don't want to go to the trouble of starting over with a new EDMX file. You can go into the app.config or web.config and DELETE the connection string line Go into the EDMX designer and delete all the tables shown there Now r-click and "update from database" as usual Viola! it will show you the "new database" wizard again just like if it was a brand new edmx

3.4.10. Two different approaches to Entity Framework modeling "Tables" The most natural and powerful way to use Entity Framework (to do most of the stuff I talk about above) is to point it at your data tables and views. EF can automatically construct super nifty VB objects that will help you do C.R.U.D. operations, custom queries, etc. "Stored procs only" But if your database model requires the use of stored procedures for EVERY operation (like BAA) then you can't take advantage of all this smartness Even just with stored procs, you can still use EF to generate nifty strongly-typed VB functions for each stored proc, *and* objects that can represent a row in each SP's result set This means instead of: Your VB code can simply do: In short, it saves you some work, makes your VB code more elegant, and less prone to errors. But (as Francis will attest) it makes naively copy-pasting old ASP code pretty well impossible. Some resources about importing stored procs Importing stored procs

3.5. Ajax Control Toolkit

3.5.1. Lectures

3.6. Authentication and Authorization ("Security")

3.6.1. For the other, more accurate definition of "Security" (cross link)

3.6.2. Lectures

3.6.3. Authentication Authentication means: prove who you are so I can map you to a user account of some kind Forms Authentication overview

3.6.4. Authorization Authorization means: Now that I know what user account you are, what things do you have access to do Authorization overwiew Roles Roles overview has the concept of "Roles". A role is a bucket you can group user accounts into. What Role a user account has can be used to define and limit their access

3.6.5. "Membership" Continuing the trend of taking a generic term that means something already, and assigning it as the name of some specific feature, we have "Membership" This is a built-in system you can use to do authentication and authorization without writing your own code. It provides login controls, automatic management of user accounts, and storage in a database Like most cool built-in things in, you probably won't really use it much. But who can say "Membership" overview If you try to use Membership features and get an error like "The user instance login flag is not supported on this version of SQL Server", then your SQL or SQL-express server needs to be set up manuall, and you have to change the configuration string a bit. Use the aspnet_regsql utility like in the lectures

3.6.6. Manual authentication You can't use the Toolbox "Login" control unless you are using the above "Membership" suite of features. If you want to do your own "quick and dirty" type of authentication, i.e. something really simple, you still can. You have to make your own form controls (easy enough) and call a couple methods in the postback to do the authentication See link showing how to create a list of valid usernames and plain-text passwords right in the web.config file itself and documentation for how to authenticate your custom form fields on the back end

3.6.7. BAA details In BAA, "Forms Authentication" is used, BUT Instead of ever showing the form, it just expects an encrypted username as a querystring argument to BaaStart.aspx And if there's no encrypted username, it assumes a public internet user, and "logs in" as that public identity more notes I made about this BaaStart is the "home page" but no one really forces browsers to go there BaaStart.aspx.vb BAARoleProvider.vb SecurityInfo.vb Site.Master.vb Page_Init

3.7. Passing information between pages, i.e. remembering "state" for a session

3.7.1. The "Session" collection

3.7.2. Other approaches

3.8. Logging information (for debugging)

3.8.1. Log4net home page

3.8.2. You can use log4net as a binary assembly (.DLL) file; it is not necessary to build it from source code.

3.8.3. A (relatively) easy way to do this is to use the NuGet package manager. Which, if you don't have it in your visual studio 2010 yet, you have to go download. Is will be a .vsix file

3.8.4. After that, you can go to "Manage NuGet Packages" in the solution's right-click menu

3.8.5. Seach for "log4net" in the upper right, and then select the first result and click "install"

3.8.6. You should now notice in the "References" section there will be a log4net item

3.8.7. Using log4net First, you have to make a configuration XML file. This will be used to tell log4net how you want it to act. See link Next you need to put a directive in your project's "My Project\AssemblyInfo.vb" file, to tell your code where the config file is. See "Attributes" section of the above link. If you don't see anything in the My Project folder, click on the Show All Files icon Now, in each VB class you put the magic "Log" property as follows: Private Shared ReadOnly Property Log As log4net.ILog Get Return log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType) End Get End Property Now anywhere in the code of that class you can say Log.DebugFormat( ... ) or Log.InfoFormat( ... ) etc. See BAA for copious examples Catching unhandled exceptions This is important! Sometimes there will be bugs that make or VB throw out an exception that you aren't expecting and catching. In order to make these things log to the log4net file instead of just breaking the app, you have to do a bit of additional work

4. Browser debugging

4.1. Lectures

4.2. unlike the videos, when you "debug" in VS, it wires up the browser's script debugging to go into VS. So, you can't do JS debugging in IE.

4.3. if you are debugging in VS too, this also explains why the "timeout exception" occurs in VS even tho it's a client side error

5. Security

5.1. Note: here I use "Security" to mean "coding in a secure manner". You will also see the term security used to mean "the code that controls login and which users can do what stuff"

5.2. For the other, more narrow and BAA use of the term "Security" (cross link)

5.3. Some best practices

5.4. Encode expressions

5.4.1. Intro

5.4.2. Demo

6. Greg's contact info

6.1. Greg at Collective Software .com