Create your own awesome maps

Even on the go

with our free apps for iPhone, iPad and Android

Get Started

Already have an account?
Log In

DOA Training by Mind Map: DOA Training
0.0 stars - reviews range from 0 to 5

DOA Training

Visual Studio 2010

Look and feel, views, tabs, dialogs, etc

Does a lot (why the UI sucks)

But you can make it like you want it

Solution

(Contains projects)

Projects

Set one as StartUp Project

Starting a new project? see ->

StartUp Project

Set a "Specific Page" as Start Action

Debugging

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

Lectures on Visual Studio debugging

Clean/Rebuild

If things are wonky and not updating properly

Clean removes all compiled output files (leaving source files)

Rebuild does that AND then builds solution.

TFS (Team Foundation Server)

Create a Team Project

Work Items

Lectures

Create, don't forget to assign to a user

There is NO search

Work Item Queries, (all, mine)

Using Version Control

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

Concepts, Revision history!, Mapping to a Local Workspace

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!

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!

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

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, Note TFS may not select these things by default, because .dll files are often "outputs", so you'll have to select these guys yourself

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:, This is bad, Hit Overwrite, but then:, Then go reconnect the solution, Your changes should now show up in the Pending Changes view, And you are good to go, 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

ASP.net

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

Page Structure

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, Has an ID that matches a Content item in the page, Will be replaced by that item's content, 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, ASP.net 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

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

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, Drag/drop onto Page Designer, You have to switch back to code view, and make sure the <uc...> tag is really where you want it, Method 2, Add @Register directive, Add a <uc...> tag

Page Elements

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

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

Server controls, Code in the ASPX page that is run on the server, There are two types, Overview of both, HTML Server Controls,, These are basically HTML tags that get generated or modified by the server, They have a "runat=server" attribute, that is how the server knows it should process something about that tag, List of some controls, About some benefits of HTML Server controls, Web Server Controls, List of some controls, These controls still look like tags, but they have an <asp:...> prefix, (and also "runat=server"), They can perform more complex sets of behavior than HTML Server controls, But there is a LOT of overlap too, And it is more confusing than it should be, YOU WILL MOSTLY USE THESE WEB SERVER CONTROLS but if you have a reason to explicitly want an HTML server control, they are under the "HTML" collapsed section in the toolbox, GridView (link to where I talk about them more), COMMENT OUT with <%-- stuff here --%>

User controls

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

Entity Framework

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

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

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), For example:, Drop down control, Grid view control, 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, Basically, when you have a string-based query in VB, and you see "it.[somecolumn]..." the "it" part is a generic placeholder that means "the object we are performing a query on", i.e. the table, view, data item, result set, etc. that is the subject of your query. It is a lot like the 'Me' or 'this' keyword, except in the context of a data query, See link in parent. also a bit more on this page, But building string queries at run time is dangerous anyway, You can use non-dynamic queries expressed in code, Note that inside the query block, you can't just mix in arbitrary VB:, Something like Convert.ToDouble( string ) will give an exception at run time., Fix this by calculating out to simple variable types first then using those in your query, Anyway, Allie's code (and your own experience) is more with stored procedures

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

"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, Regular expression, Customize using your own logic, by creating NEW completely custom attribute classes that do whatever type of crazy validation you want

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, 1, Just have an "add" link or button taking you to a separate, empty details page, and submit that in order to add., This works well if you have a "select" or "details" command anyway, where you click to view a more complete set of data about a row, 2, If your grid view really does show all the columns and you want to add rows here as if it was a sql table manager, see this link, 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, <asp:ItemTemplate> for use on "view" gridviews (as opposed to rows allowing edit inputs), <asp:EditItemTemplate> This is used when the row is "editable", Some otherwise ordinary controls can take on new features inside a grid view. Here a button is used to post back a ROW EVENT named "Select" to the VB code, and pass it an argument, You have to wire up the GridView to actually handle the events, 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

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:

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

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

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:, Instantiating ADO.NET, Connecting, Formulating a query in some manner,, being careful to map and cast the variables correctly, Disconnecting, Dealing with an ADO.NET result set and iterating through it, Mapping each value in each column to some appropriate VB type, Your VB code can simply do:, Grab an Entity Framework "Object Context" (Allies "Context" function in DB.vb does this), Call the mapped functions like it's no big deal, passing in the SP arguments as arguments to the function, get a list of objects back which contain all the data returned by the stored proc, One caveat: Output Params, These require you to do an extra DIM-new statement for each one, basically to create an empty "basket" of the correct data type, where the output param can be placed when the SP comes back, 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, MSDN article, asp.net article, another asp.net article, Importing stored procs, You cannot "see" stored procs in the EDMX design view. ONLY in the model browser tree, Even after you do your "update model from database" to pull in stored procs, you are not done yet. They are not yet mapped to functions!, Right-click on a proc and choose "Add function import", You can choose a name for the function, Click the "Get Column Information" button, and Entity Framework will examine your stored proc to see what kind of things it returns, A GOTCHA I experienced on a fresh database. if SP returns no columns, but you KNOW there are columns, go into sql mgt studio and try to exec the SP with all nulls., got this err (see link). The fix was to turn on "clr enabled" and reconfig. Then the SP worked. This is already done on your sql servers, If it returns something non-trivial (more than one item), click the "Create Complex Type" button next. This will invent a new "return type" VB class that matches the return columns. When you call the SP imported function, your return value will be a LIST of objects of this new type. See BAA, it uses this pattern extensively., On the other hand if your SP just returns one simple thing (like a number or a string), you can use the "scalar" return type (set it appropriately), And of course if the SP has no returns, then keep it at "none". Keep in mind your SP may have one or more OUTPUT params (see cross ref), After you are done monkeying with the EDMX, don't forget to BUILD. Otherwise the functions will not be shown when you intellisense on the DB Context object.

Ajax Control Toolkit

Lectures

Authentication and Authorization ("Security")

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

Lectures

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

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, 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

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

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

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, uses the asp.net role infrastructure; the role provider is specified in web.config, sets "joeuser", Session("UserRole"), and poking into form auth ticket, using formauth for its session cookie, but not actually showing form ever, BAARoleProvider.vb, Does the actual role check, calling into the security DB, couple not implemented (or needed) things, Note that all these functions are not explicitly called by OUR code,, they are called by the Role provider framework, all wired up by the web.config, SecurityInfo.vb, in the data project, IsUserInRole helper function (coincidental name to the one in role provider), gets security DB context, runs stored proc to check role, Site.Master.vb Page_Init, Checks if there's an identity, if not, call roleprovider's "LogOut" which redirs to doa home page

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

The "Session" collection

Other approaches

Logging information (for debugging)

Log4net home page

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

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

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

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

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

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 ASP.net 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, in Global.asax.vb, log in Application_Error sub, see BAA and, <http://stackoverflow.com/questions/10968370/how-to-catch-unhandled-exceptions-in-an-asp-net-application>, note that BY ITSELF this does not redirect... that is handled by the <CustomErrors> tag in web.config, <customErrors> is where you set the "Oops" page that your users will see on the front end, This just logs and then lets nature continue to take its course

Browser debugging

Lectures

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.

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

Security

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"

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

Some best practices

Encode expressions

Intro

Demo

Greg's contact info

Greg at Collective Software .com