Wednesday, November 26, 2014

MVC 4 project templates

MVC 4
Wednesday, November 26, 2014
8:47 PM
Not these project templates…..
Machine generated alternative text: Recent
Installed
Templates
D Visual Basic
A Visual C#
Windows
Web
D Office
Cloud
Reporting
D SharePoint
Silverlight
Test
WCF
Workflow
D Visual C++
D Visual F#
SQL Server
D Telerik
HDlnsight
LightSwitch
D OtherProjectTypes
Mnrlelinn Prniertc
Online
ame:
cation:
lution name:
.NETFramework4.5 Sortby. Default
ASP.NET Empty Web Application
ASP.NET Web Forms Application
ASP.NET MVC 3 Web Application
ASP.NET MVC 4 Web Application
C t:
EJ Telerik MVC Web Application
ASP.NET Dynamic Data Entities Web Application
ASP.NET AJAX Server Control
ASP.NET AJAX Server Control Extender
ASP.NET Server Control
Telerik Data Access Dynamic Data Application
Telerik Data Access Web Application
MvcApplication3
c:\users\hcovitz\documents\visual studio 2012\Projects
MvcApplication3
-
Visual C#
Visual C#
Visual C#
Visual C#
Visual C#
Visual C#
Visual C#
Visual C#
Visual C#
Visual CS
Visual CS
Search Installed Templates (Ctrl+E
Type: Visual CS
A project for creating an applical
ASP.NET MVC 4 and Web API
— Browse... j
Create directory for solution
...but the next step, THESE project templates:
Machine generated alternative text: New ASP.NET MVC 4 Project [][]
Project Template
Select a template: Description:
[ c; c; . A default ASP.NET MVC 4 project with an
account controller that uses forms
- authentication.
Empty Basic Internet Intranet
Application Application
Ct C Q’
e_i e_i ej e_J
Mobile Web API Single Page Facebook E
Application Application Application
Ct
e—J
Telerik MVC
Web Appli...
View engine:
[Razor “I
EJ Create a unit test project
Test project name:
MvcApplicationTMP.Tests
Test framework:
Visual Studio Unit Test Additional Info
j OK ] [ Cancel j
Screen clipping taken: 11/26/2014 8:32 PM
Empty
Wednesday, November 26, 2014
8:45 PM
Machine generated alternative text: New ASP.NET MVC 4 Project
Project Template
Select a template:
ri
Mobile
Application
o-J
Telerik MVC
Web Appli...
View engine:
[Razor
Description:
s
Create a unit test project
Test project name:
MvcApplicationTMP.Tests
Test framework:
[Visual Studio Unit Test
Additional Info
[ 0K j [ Cancel j
o-J
Empty
o-J
Basic
o-J
Internet
Application
ri
Single Page
Application
An empty ASP.NET MVC 4 project.
o_-J
Web API
ri
Intranet
Application
ri
Facebook
Application
vj
Screen clipping taken: 11/26/2014 8:46 PM
Machine generated alternative text: MvcApplicationTMP - Microsoft Visual Studio (Administrator) LluICI( Launch (LtrI+UJ ¿J L_. 
EDIT VIEW TELERIK PROJECT BUILD DEBUG TEAM SQL TOOLS TEST ARCHITECTURE ANALYZE WINDOW HELP
O1hI6? )—c. InternetExplorer—š9 Debug — . Subrnit—_
F Solution Explorer
Search Solution Explorer (Ctrl+;)
Solution MvcApplicationTMP (1 project)
A  MvcApphcationTMP
L’ fr Properties
L’ •-• References
• App_Data
A  App_Start
L’ C FilterConfig.cs
L’ C” RouteConfig.cs
L’ C” WebApiConfig.cs
• Controllers
• Models
A Views
4J Web.config
L’ 9 Global,asax
packagesconfig
L’ a Web.config
Screen clipping taken: 11/26/2014 8:46 PM
Basic
Wednesday, November 26, 2014
8:40 PM
Machine generated alternative text: New ASP.NET MVC 4 Project
Project Template
L1 Create a unittest project
Test project name:
MvcApplicationTMP.Tests
zJ Additional Info
OK J [ Cancel
Select a template:
ri ri
Empty Basic
Description:
A basic ASP.NET MVC 4 project.
o-j
Web API
o—j
Intranet
Application
o—j
Facebook
Application
A
o—j
Mobile
Application
ri
Telerik MVC
Web Appli...
View engine:
ri
Internet
Application
o—j
Single Page
Application
‘r
Razor
‘r
Test framework:
[sual Studio Unit Test
Screen clipping taken: 11/26/2014 8:40 PM
Machine generated alternative text: Dl MvcApplicationTMP - Microsoft Visual Studio (Administrator) Quick Launch (Ctrl+Q) p  X
FILE EDIT VIEW TELERIK PROJECT BUILD DEBUG TEAM SQL TOOLS TEST ARCHITECTURE ANALYZE WINDOW HELP
Internet Explorer e D Debug . ß . ! Submit
‘Solution Explorer
OC ‘o
Search Solution Explorer (Ctrl÷;) p
Solution ‘MvcApplicationTMP (1 project)
A  MvcApplkationTMP
L> . Properties
L> •-• References
• App_Data
I App_Staft
L> C BundleConfig.cs
L> CU FilterConfig.cs
fr CU RouteConfig.cs
L> CU WebApiConfig.cs
L> • Content
• Controllers
• Models
L> • Scripts
A J Views
L> • Shared
E@] _ViewStart.cshtml
Webconfig
L> ¿) Global.asax
Q packages.config
L> Q Web.config
Screen clipping taken: 11/26/2014 8:42 PM
Machine generated alternative text: ________________________________ ________________ P   X Theresourcecannotbefo... xl
Server Error in 7’ Application.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed. had its name changed, or is temporarily unavailable. Please review the following URL and make
Requested URL: I
Version Information: Microsoft NET Framework Version:4.0.3031 9; ASP.NET Version:4.0.30319.1 8067
Access is denied.
Screen clipping taken: 11/26/2014 8:43 PM
Internet Application
Wednesday, November 26, 2014
8:20 PM
Machine generated alternative text: New ASP.NET MVC 4 Project [][]
Project Template
Select a template: Description:
[ c; c; . A default ASP.NET MVC 4 project with an
account controller that uses forms
- authentication.
Empty Basic Internet Intranet
Application Application
Ct C Q’
e_i e_i ej e_J
Mobile Web API Single Page Facebook E
Application Application Application
Ct
e—J
Telerik MVC
Web Appli...
View engine:
[Razor “I
EJ Create a unit test project
Test project name:
MvcApplicationTMP.Tests
Test framework:
Visual Studio Unit Test Additional Info
j OK ] [ Cancel j
Screen clipping taken: 11/26/2014 8:32 PM
Machine generated alternative text: Register Log in
Home About Contact
.. .
ETMVCafcio)
s, and samples to help you get the most from
After you run it and Register a user, creates db.
Machine generated alternative text: 1 Solution NHLSPstraw’ (1 project)
A  NHISPstraw
L’ fr Properties
L’ •-• References
A  App_Data
n aspnet-NHLSPstraw-20141126201745.mdf
A  App_Start
fr C” AuthConfig.cs
fr C” BundleConfig.cs
k r.. r:i.r
Screen clipping taken: 11/26/2014 8:24 PM
Intranet Application
Wednesday, November 26, 2014
8:35 PM
Machine generated alternative text: New ASP.NET MVC 4 Project L
Proj cd Template
Select a template: - - Description:
A default ASP.NET MVC 4 project that
fl uses Windows authentication or Windows
. Azure authentication.
Empty Basic Internet Intranet
Application Application
ca
e—’ e—J e- e-
Mobile Web API Single Page Facebook
Application Application Application
e-
Telerik MVC
Web Appli...
View engine:
Razor
I Createaunittest project
Test project name:
MvcApplicationTMP.Tests
Test framework:
[Visual Studio Unit Test Additional Info
Screen clipping taken: 11/26/2014 8:36 PM
Machine generated alternative text: cq MvcApplicationTMP - Microsoft Visual Studio (Administrator) Quick Launch (Ctrl÷Q) ¿J — 0 X
FILE EDIT VIEW TELERIK PROJECT BUILD DEBUG TEAM SQL TOOLS TEST ARCHITECTURE ANALYZE WINDOW HELP
QeO ejhIi 9_ÇÍe InternetExplorereD Debug e I ‘•4’d>_ e Submit—..
Solution Explorer _________
- V #QdiHÌ
a
Otherwise, to use this template with Windows authentication, refer to the instructions below:
Hosting on 115 Express:
1. Click on your project in the Solution Explorer to select the project.
2. If the Properties pane is not open, open it (F4).  Properties
3. In the Properties pane for your project: •-• References
a) Set “Anonymous Authentication” to “Disabled”. • App_Data
b) Set “Windows Authentication” to “Enabled”. A  App_Start
L> Ct BundleConfig.cs
Hosting on IlS 7 or later: L> O’ FilterConfig.cs
1. Open IlS Manager and navigate to your website. > 0’ RouteConfig.cs
2. In Features View, double-click Authentication.
3. On the Authentication page, select Windows authentication. If Windows L’ 0’ WebApiConfig.cs
L’ • Content
authentication is not an option, you’ll need to make sure Windows authentication
is installed on the server. A  Controllers
L> C’ HomeController.cs
To enable Windows authentication on Windows: > • Images
a) In Control Panel open “Programs and Features”. • Models
b) Select “Turn Windows features on or off”. > • Scripts
c) Navigate to Internet Information Services > World Wide Web Services > Security A  Views
and make sure the Windows authentication node is checked.
> • Home
To enable Windows authentication on Windows Server: >  Shared
a) In Server Manager, select Web Server (IlS) and click Add Role Services. [@] _ViewStart,cshtml
b) Navigate to Web Server > Security Q Web.config
and make sure the Windows authentication node is checked. D faviconico
> ¿ Global.asax
4. In the Actions pane, click Enable to use Windows authentication. Q packages.config
5. On the Authentication page, select Anonymous authentication. D readme.txt
6. In the Actions pane, click Disable to disable anonymous authentication.
> Q Webconfig
template with Windows Azure authentication,
Screen clipping taken: 11/26/2014 8:52 PM
Machine generated alternative text: nttr: localhost:16286/ .0  C X I Access is denied.
Server Error in ‘I’ Application.
Access is denied.
Description: An error occurred while accessing the resources required to serve this request. The server may not be configured for access to the requested URL.
Error message 401.2.: Unauthorized: Logon failed due to server configuration. Verify that you have permission to view this directory or page based on the credentials you supplied and the a
the Web server’s administrator for additional assistance.
Version Information: Microsoft .NET Framework Version:4.O.30319; ASP.NET Version:4.O.30319.1 8067
Access is denied.
Screen clipping taken: 11/26/2014 8:53 PM

Created with Microsoft OneNote 2010
One place for all your notes and information

Tuesday, November 25, 2014

Sure, throw a null-coalescing operator into an intro tutorial on MVC EF


"
int pageSize = 3;
int pageNumber = (page ?? 1);
return View(students.ToPagedList(pageNumber, pageSize));
The ToPagedList method takes a page number. The two question marks represent the null-coalescing operator. The null-coalescing operator defines a default value for a nullable type; the expression (page ?? 1) means return the value of page if it has a value, or return 1 if page is null.
"

Can't be surprised since he loves the Ternary Operator.



Some links on Ternary Operators:

http://stackoverflow.com/questions/694814/ternary-operator-bad-or-best-practice

http://programmers.stackexchange.com/questions/28314/ternary-operator-considered-harmful

http://thedailywtf.com/articles/One-Bad-Ternary-Operator-Deserves-Another

https://agiletribe.wordpress.com/2011/11/01/21-avoid-ternary-conditional-operator/

http://discuss.fogcreek.com/joelonsoftware/default.asp?cmd=show&ixpost=142517

http://en.wikipedia.org/wiki/Talk%3A%3F%3A
"I don't know how to do so, but this page should be flagged as being a very biased viewpoint. The text runs counter to my experience of 20+ years as a professional software programmer. The only people who prefer the ternary conditional operator to the more readable if-then-else format (when both are allowed by the language syntax) are those people who have never had to maintain other people's code bases for any significant period of time. This opinion is found in industry standard texts, such as "Code Complete" by Steve McConnell. I would love to see a valid citation supporting the viewpoint presented here, i.e. that the ternary operator is NOT considered to be antiquated, harder to debug, and harder to maintain."

Friday, November 21, 2014

Azure and FTP

"
To use an FTP tool, you need three things: the FTP URL, the user name, and the password.
The URL is shown on the web site's dashboard page in the Windows Azure Management Portal, and the user name and password for FTP can be found in the .publishsettings file that you downloaded earlier. The following steps show how to get these values.
  1. In the Windows Azure Management Portal, click Web Sites tab and then click the staging web site.
  2. On the Dashboard page, scroll down to find the FTP host name in the Quick Glance section.
    FTP host name
  3. Open the staging .publishsettings file in Notepad or another text editor.
  4. Find the publishProfile element for the FTP profile.
  5. Copy the userName and userPWD values.
    FTP credentials
  6. Open your FTP tool and log on to the FTP URL.
  7. Copy app_offline.htm from the solution folder to the /site/wwwroot folder in the staging site.
    Copy app_offline
  8. Browse to your staging site's URL. You see that the app_offline.htm page is now displayed instead of your home page."



UPDATE
Getting this, so doesn't seem to work:
Response: 150 File status okay; about to open data connection.
Error: Connection timed out
Error: Failed to retrieve directory listing

Thursday, November 20, 2014

Random MVC EF stuff

"The Required attribute is not needed for value types such as DateTime, int, double, and float. Value types cannot be assigned a null value, so they are inherently required. "

"

The ForeignKey Attribute

When there is a  one-to-zero-or-one relationship or a  one-to-one relationship between two entities (such as betweenOfficeAssignment and Instructor), EF can't work out which end of the relationship is the principal and which end is dependent.  One-to-one relationships have a reference navigation property in each class to the other class. TheForeignKey Attribute can be applied to the dependent class to establish the relationship. If you omit the ForeignKey Attribute, you get the following error when you try to create the migration:
Unable to determine the principal end of an association between the types 'ContosoUniversity.Models.OfficeAssignment' and 'ContosoUniversity.Models.Instructor'. The principal end of this association must be explicitly configured using either the relationship fluent API or data annotations."



..later one we learn:

"The course entity has a foreign key property DepartmentID which points to the related Department entity and it has aDepartment navigation property. The Entity Framework doesn't require you to add a foreign key property to your data model when you have a navigation property for a related entity.  EF automatically creates foreign keys in the database wherever they are needed. But having the foreign key in the data model can make updates simpler and more efficient. For example, when you fetch a course entity to edit, the  Department entity is null if you don't load it, so when you update the course entity, you would have to first fetch the  Department entity. When the foreign key propertyDepartmentID is included in the data model, you don't need to fetch the Department entity before you update."


Microsoft Azure Obfuscation

"Your Windows Azure Web Site will run in a shared hosting environment, which means it runs on virtual machines (VMs) that are shared with other Windows Azure clients. A shared hosting environment is a low-cost way to get started in the cloud. Later, if your web traffic increases, the application can scale to meet the need by running on dedicated VMs. If you need a more complex architecture, you can migrate to a Windows Azure Cloud Service. Cloud services run on dedicated VMs that you can configure according to your needs."

I added color and highlights ... but I'm not sure that is what Microsoft meant.

Friday, November 14, 2014

SQL Server Express vs. LocalDB

The user instance feature in SQL Server Express also enables you to work with .mdf files, but the user instance feature is deprecated; therefore, LocalDB is recommended for working with .mdf files.
Typically SQL Server Express is not used for production web applications. LocalDB in particular is not recommended for production use with a web application because it is not designed to work with IIS.

In Visual Studio 2012 and later versions, LocalDB is installed by default with Visual Studio. In Visual Studio 2010 and earlier versions, SQL Server Express (without LocalDB) is installed by default with Visual Studio.

C# Virtual vs Abstract

MVC with Entity Framework is forcing us to revisit some details of the C# language that seemed obscure or esoteric at the time we learned them.

LINQ famously did the same (with stuff that only came with # 2.0), with Generics, Delegates, Anonymous Methods, Enumerators and Yield,
(and from C# 3.0, as if created only for the purpose of later usage with LINQ) Local Type Inference, Lambda Expressions, Extension Methods, Object Initialization Expressions, Anonymous Types, and Query Expressions.

An abstract function can have no functionality. You're basically saying, any child class MUST give their own version of this method, however it's too general to even try to implement in the parent class.

A virtual function, is basically saying look, here's the functionality that may or may not be good enough for the child class. So if it is good enough, use this method, if not, then override me, and provide your own functionality.

TODO:
Describe difference between virtual function as opposed to virtual properties.

NB: This post inherited from http://stackoverflow.com/questions/391483/what-is-the-difference-between-an-abstract-function-and-a-virtual-function