Computer
Microsoft Asp.Net
search
Microsoft Asp.Net
See Also
Microsoft Windows Server
Microsoft Windows Run Command
Microsoft Internet Information Services
Windows Powershell
Microsoft Windows
Microsoft Sql Server
Precautions
Non-Medical
Not for Medical Care
The author uses several software packages and programming languages to develop FPnotebook content
For convenience, a dozen pages in FPNotebook are dedicated to quick notes on content creation
Management
Vulnerabilities
SQL Injection
Use parameterized sql queries (or use ORM such as entity framework)
Avoid dynamic query construction at run-time
Cross-Site Scripting
Javascript is disabled by default in MVC input fields
Beware the raw MVC tag helper
Cross Site Request Forgery (CSRF)
Add
to controller post/put/delete methods
Add @Html.AntiForgeryToken to inside of form markup on MVC page
Results in a token hidden field created within the form, and encrypted token in a cookie
Two token sources (cookie and hidden field) must match on calling MVC controller
Management
DotNet5 Setup
DotNet Version Manager (DNVM)
Used for command line selection of dotNet version for compiling (clr or CoreClr, x64 or x86)
Visual Studio
sets this inside of project properties (but
VS Code
would use command line)
After installing dotnet and restarting, go to command line in user directory
Follow the following steps
DNVM Setup
Sets path names
DNVM Upgrade
Installs latest version of dotnet (but only x86, not x64 or coreClr)
DNVM List
Lists the current installed dotnet versions
DNVM Install
-arch
-r
Type most uptodate file version in the list
Install any or all of the 4 versions
DNVM alias default
-arch
-r
Set the default version of DotNet
DNVM use
-arch
-r
-p
Set the version of DotNet to use currently
The -p switch persists this selection
References
Shawn Wildermuth (2015) Pluralsight, Building a Web App with asp.net 5, accessed 12/2/2015
Management
Identity with Identity Server 4
Setup identity server
In
Visual Studio
, create a dotnet core web application with individual accounts
Add "IdentityServer4" and "identityServer4.aspNetIdentity" Nuget packages
Add to startup.configureServices: AddDeveloperIdentityServer(), and replace with AddIdentityServer in production
In program.cs, addUrl("http://localhost:5000") or whichever host url
In project properties, change to run as project name console app (not IISExpress) and uncheck launch browser
Copy over the IdentityServer4.Quickstart.UI contents to added controllers, models and views for authentication
This is primarily for consent and logout pages (asp.net identity covers the login)
Setup google oauth
Use the google developer's console - apis
Create a project
Under library tab, add "Google+api" (important!)
Add credentials - oauth
Set base url (or leave blank for testing e.g. localhost)
Set redirect (url/signin-google)
Visualization
IdentityServer Connection Info (when set to AddDeveloperIdentityServer)
Url:5000/.well-known/openid-configuration
Json Access Token
Website: jwt.io
Paste the json access token contents into the jwt.io input area and view header and data
Resources
http://docs.identityserver.io/en/dev/quickstarts/6_aspnet_identity.html
Management
Api
Visualization
Postman (chrome plug-in)
Nuget package Swagger
Startup ConfigureServices: services.AddSwaggerGen()
Startup Configure: app.UseSwaggerGen(), app.UseSwaggerUi()
Navigate to localhost/swagger/ui
Management
Visual Studio
Project set-up of simple web site
Use new project wizard, select ASP.NET Core project (and empty, api, or full/mvc)
Add Identity (individual accounts)
Program.cs will "Use IISIntegration()"
Node/Grunt/Gulp/Bower
Assumes Node is already installed on machine
Assumes
Visual Studio
2015 or Nuget Node Plug-ins are installed
Add package.json
Analogous to Nuget package installation for C#
Installs node plugin dependencies for the current dir to project directory
In Solution Explorer, Right click on the packages.json and click "NPM Install Packages"
Replaces bower for most cases
Add bower.json (or use npm/package.json instead)
http://bower.io/docs/creating-packages/
Installs the javascript dependencies (e.g. angular, bootstrap, jquery, d3)
Add dependencies in json format (see link above)
In Solution Explorer, Right click on the packages.json and click "Bower Install Packages"
Malformed Error may occur (due to
Visual Studio
inserting a BOM character in the file)
If malformed error, open in editor (e.g. Notepad++, Sublime) and Save As "UTF8 without BOM"
Add Gruntfile.js
http://gruntjs.com/sample-gruntfile
Task runner with numerous plugins for any purpose (e.g. LESS/SASS, minify/uglify, convert...)
Add Gulpfile.js (optional alternative to Grunt)
https://github.com/gulpjs/gulp
Task runner that allows more sequential steps for each file opened
Younger than Grunt, so less plugins available, but very active development in 2015
Great for writing quick, custom javascript tasks that combine multiple steps on a single file
Example: Use load an XML file, convert to json (plug-in), custom modify it, then save the json
Management
SqlServer Integration with Asp.Net MVC
Application pool access
Create an application pool in IIS
Confirm that the application pool has Identity = ApplicationPoolIdentity (advanced settings)
Assign the MVC application pool to the application
Use Sql Server Management Studio to add the application pool to Sql logins
Right click Security\Logins and choose "New Login"
Login name: IIS APPPOOL[name of your application pool]
Do not click search (it will not find the apppool)
Leave as windows authentication
Server Roles
Public
User Mapping
Select the database(s)
Role membership: db_datareader, db_datawriter, public (give no more access than needed)
References
Configuring an MVC4/IIS app to access SQL Server
http://rarcher.azurewebsites.net/Post/PostContent/20
Management
Web Deploy (
Visual Studio
)
Manually updating web.config on server
Publishing web.config overwrites server settings
Good for newly added components, bad for SQL Connections
Deployment settings SQL connections for servers is tricky
Added to project file (csproj), under properties
<ExcludeFilesFromDeployment>web.config</...>
Do not forget to manually copy new settings when components are added
Type your search phrase here