DOA Training

Commencez. C'est gratuit
ou s'inscrire avec votre adresse courriel
Rocket clouds
DOA Training par 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)

1.5.1.1. Saves all files

1.5.1.2. Builds solution

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

2.2.4.1. (all, mine)

2.3. Using Version Control

2.3.1. Navigating

2.3.1.1. How to Connect to TFS

2.3.1.2. View Source Control

2.3.1.2.1. View->Team Explorer

2.3.1.2.2. Double Click "Source Control"

2.3.1.3. View Local project files

2.3.1.3.1. View -> Solution Explorer

2.3.2. Concepts

2.3.2.1. Revision history!

2.3.2.2. Mapping to a Local Workspace

2.3.3. If you are starting a new Project

2.3.3.1. Workspace dropdown -> "Workspaces ..." -> Add

2.3.3.2. Choose a Local Path

2.3.3.3. Create a "DEV" branch

2.3.3.3.1. Right click the Team Project

2.3.3.3.2. Create a folder "DEV"

2.3.3.3.3. Check in

2.3.3.3.4. Right click "DEV" folder

2.3.3.3.5. Branching -> Convert to branch

2.3.3.4. File -> New Project

2.3.3.5. ASP.NET Web Application

2.3.3.5.1. Target correct framework version

2.3.3.6. Name the solution

2.3.3.7. Check "Add to Source Control"

2.3.3.8. Choose the "DEV" branch as where to store it in source control

2.3.3.9. Choose the local workspace you created above

2.3.3.10. Now you have a Solution, a default project, and a ton of automatically generated files

2.3.3.11. Missing files?

2.3.3.12. Don't forget to check in your files to source control!

2.3.4. Importing an Existing Project that is NOT in TFS yet

2.3.4.1. Connect to TFS

2.3.4.2. Add a new Workspace and map it to a path on your C:\ drive

2.3.4.2.1. Source control

2.3.4.2.2. Workspaces

2.3.4.2.3. Add

2.3.4.2.4. Configure

2.3.4.2.5. Next, browse for and select (or make a new) local folder. This is where the workspace will "live" on this machine

2.3.4.3. Make a folder to store your work in source control

2.3.4.3.1. add

2.3.4.4. Import project files

2.3.4.4.1. Explore

2.3.4.4.2. Go into new sub-folder in explorer

2.3.4.4.3. Put the project files into this directory

2.3.4.4.4. Add new stuff to source control

2.3.4.4.5. Select

2.3.4.4.6. Select any LIB items that are excluded, and then click "Include items"

2.3.4.4.7. Click Finish

2.3.4.5. Bind the solution to source control

2.3.4.5.1. Find the solution in the source control explorer window, and open it

2.3.4.5.2. Bind

2.3.4.5.3. select and bind, then click OK

2.3.4.5.4. Now in Solution explorer you should have the solution open

2.3.4.5.5. Make sure it builds and runs ok

2.3.4.5.6. Check in!

2.3.5. Working on an Existing Project already in TFS

2.3.5.1. Get the Source Code

2.3.5.2. Double click on the Solution (.sln) file to open

2.3.6. Adding files to Source Control

2.3.6.1. If you are adding libraries or files to the project, you need to figure out what files "should" be in source control

2.3.6.2. In general, you do NOT add

2.3.6.2.1. /obj: This folder contains intermediate files used during compilation

2.3.6.2.2. /bin: This folder contains output files generated from the compilation

2.3.6.3. In general, you DO add:

2.3.6.3.1. Folders containing source files (aspx, vb, etc)

2.3.6.3.2. /lib folders and the binary files they contain

2.3.7. Daily routine

2.3.7.1. Team Explorer

2.3.7.2. Double-click "Source Control"

2.3.7.3. Right-click project -> Get Specific Version

2.3.7.4. Make code additions, changes, etc.

2.3.7.4.1. If you add a file, select "Add to source control" checkbox!

2.3.7.4.2. When you edit a file, it should automatically become checked out and show up in pending changes

2.3.7.4.3. If you lose connection to TFS, you will see:

2.3.7.5. View -> Other Windows -> Pending Changes

2.3.7.6. Get a list of your Work Items

2.3.7.7. You can associate work items with your changes when you check in

2.3.7.8. Make sure the Workspace here is the same as the one in Source Control Explorer

2.3.7.9. Check in

3. ASP.net

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

3.2. Page Structure

3.2.1. Master Page

3.2.1.1. This is the template for the site

3.2.1.2. It holds the HTML structure and content that is *common* across all pages

3.2.1.2.1. <html>

3.2.1.2.2. <head>

3.2.1.2.3. <body>

3.2.1.3. How does one Master display different contents for different pages?

3.2.1.3.1. asp:ContentPlaceholder

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

3.2.1.5. Beware "Page Title" weirdness

3.2.1.5.1. ASP.net has some odd handling of page titles

3.2.1.5.2. What you put into the <title> tag in your master page will be overwritten

3.2.1.5.3. By what's in the aspx page Title attribute at the top

3.2.1.5.4. or the .Title property in the page's codebehind

3.2.1.5.5. AND... if you omit the title tag from the master page, an EMPTY one will be added (uselessly)

3.2.1.5.6. See discussions on this page for more info

3.2.2. Pages

3.2.2.1. Files with .aspx extension

3.2.2.1.1. These are the pages of your site

3.2.2.2. One page is more or less a "screen"

3.2.2.3. Code behind

3.2.2.3.1. Server-side VB code that is unique to this page will go in the "code behind" VB file.

3.2.2.3.2. Note the *similar* name, but followed by .vb

3.2.2.4. Each content page refers to its master

3.2.2.4.1. _

3.2.2.5. Notice there are no template/outer HTML tags

3.2.2.6. Has asp:Content items

3.2.2.6.1. Each Content item has a ContentPlaceHolderID

3.2.2.6.2. This matches a placeholder in Master

3.2.2.7. To add a page...

3.2.2.7.1. To add a page

3.2.3. Web User controls

3.2.3.1. Idea:

3.2.3.1.1. A re-useable chunk of UI and code

3.2.3.1.2. Something modular

3.2.3.1.3. Something you want on some pages, but not others

3.2.3.1.4. Like a navigation control, or a calendar picker

3.2.3.1.5. Easier than making multiple Master pages

3.2.3.1.6. Easier than copy/pasting content between pages

3.2.3.2. Will be added to one or more content pages

3.2.3.3. .ascx files

3.2.3.4. To make a new control...

3.2.3.4.1. ...

3.2.3.5. MSDN uberpage

3.2.3.6. Adding a user control to Master, or to a page

3.2.3.6.1. Method 1

3.2.3.6.2. Method 2

3.3. Page Elements

3.3.1. Overviews

3.3.1.1. PluralSight lecture

3.3.1.2. MSDN

3.3.1.3. W3Schools (a bit dated; easier to read)

3.3.2. HTML tags

3.3.2.1. The fundamental language of web browsers

3.3.2.2. Code in the ASPX page that is passed AS-IS to the browser

3.3.2.3. <tags> that do not have any <namespace:...> prefix

3.3.2.4. And they do not have any "runat=server" attribute

3.3.2.5. <a>, <p>, <div>, <span>, <h1>, etc.

3.3.2.6. COMMENT OUT with <!-- stuff here -->

3.3.3. Server controls

3.3.3.1. Code in the ASPX page that is run on the server

3.3.3.2. There are two types

3.3.3.2.1. Overview of both

3.3.3.2.2. HTML Server Controls,

3.3.3.2.3. Web Server Controls

3.3.3.3. COMMENT OUT with <%-- stuff here --%>

3.3.4. User controls

3.3.5. CSS

3.3.5.1. Lecture series

3.3.5.2. A great resource link

3.3.5.3. "Cascading Style Sheets"

3.3.5.4. Information for the browser about how the site should be rendered (colors, sizes, positions, hiding/showing of certain elements)

3.3.5.5. Parsed by the web browser only (no server side scripting, VB code, etc.)

3.3.5.6. One is created by default, and automatically referenced by the master page

3.3.5.6.1. .

3.4. Entity Framework

3.4.1. Lectures

3.4.1.1. Create a model from a database

3.4.1.2. Exploring the classes generated from an Entity Data Model

3.4.1.3. Consuming an Entity Model from a separate .NET project

3.4.1.4. LINQ to Entities

3.4.1.5. Updating database items

3.4.2. .EDMX files

3.4.2.1. This is the file type that controls and instructs the generation of VB<-->database code

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

3.4.3.1. How things are related

3.4.3.2. We used two types of controls:

3.4.3.2.1. Web controls (to display or edit data in the browser)

3.4.3.2.2. Data Source controls (they provide connectivity from Entity objects to the Web controls)

3.4.3.2.3. They are NOT THE SAME

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

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

3.4.3.3. Menus and smart tags

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

3.4.3.3.2. IMPORTANT: these tags show and hide based on what thing you have currently SELECTED with the mouse (left click)

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

3.4.3.4. Data binding issues

3.4.3.4.1. When there are 2 separate projects (Data and Web), you need to copy the connection string into both of them.

3.4.3.4.2. In the Data project it goes in app.config.

3.4.3.4.3. In the Web project, it goes in web.config

3.4.3.5. Performing queries in VB code

3.4.3.5.1. The "it" string

3.4.3.5.2. But building string queries at run time is dangerous anyway

3.4.3.5.3. You can use non-dynamic queries expressed in code

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

3.4.4.1. How do you create a connection string property for web.config (etc.)?

3.4.4.2. You can go into Server Explorer, and add a Data Connection

3.4.4.3. Work out the server, instance name, credentials, etc. etc. and click "Test connection"

3.4.4.4. If that works, then save it with "OK"

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

3.4.5.1. Lecture (series)

3.4.5.2. NOTE: this is NOT useable if you are using the "stored proc only" approach to data access

3.4.5.3. You can add these capabilities to an existing project, in the following hacky manner:

3.4.5.4. A Dynamic Data site gives you a ton of "Scaffolding" code, which can then be edited and customized per your needs.

3.4.5.5. What this does, and how it works

3.4.5.6. customization

3.4.5.6.1. To customize items, you do NOT edit the class in the edmx Designer.vb file, because that will get overwritten each time

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

3.4.5.6.3. Customize data field validation using existing normal-ish attributes

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

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

3.4.6.2. What about *adding* a row?

3.4.6.2.1. OK, this is non-trivial. There are basically 2 schools of thought

3.4.6.3. Validation (see cross link)

3.4.6.3.1. In order to do something non-default with the column, go into the column editor and click the "convert to template column" link

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

3.4.6.4. "My grid view isn't showing any data"

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

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

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

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

3.4.6.5. Bound vs. Template fields

3.4.6.5.1. When you define your own columns, you can use the <asp:BoundField...> sub-tag to describe a field that doesn't require any validation.

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

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

3.4.7.1. use the <asp:*Validator> controls, like in the lectures

3.4.7.2. SUPER IMPORTANT: Do not trust or commit any code from the page unless you run the SERVER SIDE VALIDATION TOO (see link)

3.4.7.2.1. First, you need to call "Validate()" unless the control that posted back has CausesValidation=true

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

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

3.4.7.4. One cryptic "GOTCHA" error I encountered

3.4.7.4.1. Invalid postback or callback argument. Event validation is enabled using '<pages enableEventValidation=“true”/>'

3.4.7.4.2. See link:

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

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

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

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

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

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

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

3.4.9.2. You can go into the app.config or web.config and DELETE the connection string line

3.4.9.3. Go into the EDMX designer and delete all the tables shown there

3.4.9.4. Now r-click and "update from database" as usual

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

3.4.10.1. "Tables"

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

3.4.10.2. "Stored procs only"

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

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

3.4.10.2.3. This means instead of:

3.4.10.2.4. Your VB code can simply do:

3.4.10.2.5. In short, it saves you some work, makes your VB code more elegant, and less prone to errors.

3.4.10.2.6. But (as Francis will attest) it makes naively copy-pasting old ASP code pretty well impossible.

3.4.10.2.7. Some resources about importing stored procs

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

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

3.6.3.2. Forms Authentication overview

3.6.4. Authorization

3.6.4.1. Authorization means: Now that I know what user account you are, what things do you have access to do

3.6.4.2. Authorization overwiew

3.6.4.3. Roles

3.6.4.3.1. Roles overview

3.6.4.3.2. ASP.net 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. ASP.net "Membership"

3.6.5.1. Continuing the trend of taking a generic term that means something already, and assigning it as the name of some specific ASP.net feature, we have "Membership"

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

3.6.5.3. Like most cool built-in things in ASP.net, you probably won't really use it much. But who can say

3.6.5.4. "Membership" overview

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

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

3.6.6.2. See link showing how to create a list of valid usernames and plain-text passwords right in the web.config file itself

3.6.6.3. and documentation for how to authenticate your custom form fields on the back end

3.6.7. BAA details

3.6.7.1. In BAA, "Forms Authentication" is used, BUT

3.6.7.2. Instead of ever showing the form, it just expects an encrypted username as a querystring argument to BaaStart.aspx

3.6.7.3. And if there's no encrypted username, it assumes a public internet user, and "logs in" as that public identity

3.6.7.4. more notes I made about this

3.6.7.4.1. BaaStart is the "home page" but no one really forces browsers to go there

3.6.7.4.2. BaaStart.aspx.vb

3.6.7.4.3. BAARoleProvider.vb

3.6.7.4.4. SecurityInfo.vb

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

3.8.7.1. First, you have to make a configuration XML file. This will be used to tell log4net how you want it to act. See link

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

3.8.7.3. Now, in each VB class you put the magic "Log" property as follows:

3.8.7.3.1. Private Shared ReadOnly Property Log As log4net.ILog Get Return log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType) End Get End Property

3.8.7.4. Now anywhere in the code of that class you can say Log.DebugFormat( ... ) or Log.InfoFormat( ... ) etc.

3.8.7.5. See BAA for copious examples

3.8.7.6. Catching unhandled exceptions

3.8.7.6.1. This is important!

3.8.7.6.2. Sometimes there will be bugs that make ASP.net or VB throw out an exception that you aren't expecting and catching.

3.8.7.6.3. 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 ASP.net 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