Study Guide For Exam 70-486 Developing ASP - NET MVC 4 Web Applications
Study Guide For Exam 70-486 Developing ASP - NET MVC 4 Web Applications
Study Guide For Exam 70-486 Developing ASP - NET MVC 4 Web Applications
if (!namespaceManager.QueueExists("TestQueue"))
{
namespaceManager.CreateQueue(qd);
}
● QueueClient Client =
QueueClient.CreateFromConnectionString(connectionString, "TestQueue");
Client.Send(new BrokeredMessage());
● BrokeredMessage message = Client.Receive();
Console.WriteLine("Body: " + message.GetBody<string>());
Console.WriteLine("MessageID: " + message.MessageId);
Console.WriteLine("Test Property: " +
message.Properties["TestProperty"]);
<InputEndpoints>
<InputEndpoint name="HttpIn" port="80" protocol="http"/>
<InputEndpoint certificate="Certificate1" name="HttpsIn" port="443" protocol="https"/>
</InputEndpoints>
<InternalEndpoint name="InternalHttpIn" protocol="http"/>
●
● Configure state management.
○ This objective may include but is not limited to: choose a state management mechanism (in-process and
out of process state management, ViewState); plan for scalability; use cookies or local storage to
maintain state; apply configuration settings in web.config file; implement sessionless state (for example,
QueryString)
■ session state: in-process, out of process, sql server mode
● <configuration>
<sessionstate
mode="sqlserver"
cookieless="false"
timeout="20"
sqlconnectionstring="data source=MySqlServer;
user id=ASPState;
password=1Gr8State"
server="127.0.0.1"
port="42424"
/>
● sqlconnectionstring="data source=127.0.0.1;user
id=<user id>;password=<password>"
● Design a caching strategy.
○ This objective may include but is not limited to: implement page output caching (performance oriented);
implement data caching; implement HTTP caching
■ Azure in memory caching
● nuget package: azure caching...
● in your code:
● DataCache cache
● cache.Get(name)
● cache.Add(name, data)
● cache.Put(name, data)
■ Old way of caching: System.Web.Caching
● [OutputCache(Duration, VaryByParam, VaryByContentEncoding,
VaryByHeader, CacheProfile)] in action or controller
● data caching with good old Cache[“name”]
● Cache.Add(key, value, CacheDependency, DateTime, TimeSpan,
CacheItemPriority, CacheItemRemovedCallback)
○ (CacheDependency can point out file path)
■ New ways to cache in .NET 4 System.Runtime.Caching
● ObjectCache // abstract, implemented by
● MemoryCache
○ Add, Set, Get, Remove
ObjectCache cache = MemoryCache.Default;
string fileContents = cache["filecontents"] as string;
if (fileContents == null)
{
CacheItemPolicy policy = new CacheItemPolicy();
policy.AbsoluteExpiration =
DateTimeOffset.Now.AddSeconds(60.0);
policy.ChangeMonitors.Add(new
HostFileChangeMonitor(filePaths));
<providers>
<add
name="OdbcProvider"
type="Samples.AspNet.Membership.OdbcMembershipProvider"
connectionStringName="OdbcServices"
enablePasswordRetrieval="true"
enablePasswordReset="true"
requiresQuestionAndAnswer="true"
writeExceptionsToEventLog="true" />
</providers>
</membership>
■ Thread.GetDomain().SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
■ WindowsPrincipal myPrincipal = (WindowsPrincipal)Thread.CurrentPrincipal;
● Configure and apply authorization.
○ This objective may include but is not limited to: create roles; authorize roles by using configuration;
authorize roles programmatically ; create custom role providers; implement WCF service authorization
■ WCF Service authorization?
● Security: Message based or transport based
● role based authorization
● IIdentity currentUser =
● ServiceSecurityContext.Current.PrimaryIdentity;
● if (Roles.IsUserInRole(currentUser.Name, "Member"))
■ create custom role providers?
● Inherit RoleProvider, implement many required methods
○ CreateRole
○ AddUsersToRole
○ IsUserInRole(string, string)
● Design and implement claims-based authentication across federated identity stores.
○ This objective may include but is not limited to: implement federated authentication by using Windows
Azure Access Control Service; create a custom security token by using Windows Identity Foundation;
handle token formats (for example, oAuth, OpenID, LiveID, and Facebook) for SAML and SWT tokens
■ how to implement oauth, livied, fb etc on your mvc site
■ OAuthWebSecurity.RegisterTwitterClient
■ OAuthWebSecurity.RegisterFacebookClient(
■ appId: "",
■ appSecret: "");
■ OAuthWebSecurity.RegisterMicrosoftClient
■ OAuthWebSecurity.RegisterGoogleClien
■ Claims:
■ ClaimsPrincipal now base class to WindowsPrincipal, GenericPrincipal, RolePrincipal
■ Claims are not what the subject can and cannot do. They are what the subject is or is
not.authenitcated/issued by the Security Token Service (STS) (aka Identity provider)
■ A Claim object has claim Type, Value and ValueType (givenname, “klas”, string)
■ Claims are grouped in a Token that is signed. SAML (Security Assertion Markup
Language) and SWT (Simple web Token) are formats. Relaying Party (RP) is the using
web site.
■ Both ClaimsPrincipal and CliamsIdentity have Claims, use the principal
■ ClaimsPrincipalPermission.CheckAccess to check access in code
■ ClaimsAuthenticationManager.Authenticate can be subclassed and implemented to
intercept ClaimsIdentityCollection and modify it
■ You can configure a web-based application with a custom claims authorization manager,
an instance of a class that derives from the ClaimsAuthorizationManager class. When
so configured, the request processing pipeline packages the incoming ClaimsPrincipal
in an AuthorizationContext and invokes the CheckAccess method on your claims
authorization manager. ClaimsPrincipalPermissionAttribute can be used to protect
code
● <applicationService>
<claimsAuthorizationManager>
■ The RP gets the ClaimsPrincipal principal = HttpContext.Current.User as
ClaimsPrincipal;
■ a Federated Provider (FP) lies between RP and Identity Providers and transforms claims
in a way that RP understands. Windows Azure Access Control Service (ACS) is a FP
■ How to write custom tokens in WIF - subclass SecurityTokenHandler and SecurityToken.
Web.config in RP needs a <microsoft.identityModel> with <federatedAuthetication> that
specifies the STS used
● Manage data integrity.
○ This objective may include but is not limited to: apply encryption to application data; apply encryption to
the configuration sections of an application; sign application data to prevent tampering
■ encrypt data
● Rijndael alg = Rijndael.Create();
alg.Key = Key;
alg.IV = IV;
cs = new CryptoStream(ms, alg.CreateEncryptor(),
CryptoStreamMode.Write);
■ encrypt configuration sections
■ create keys (exportable in CSP):
● aspnet_regiis -pc "SampleKeys" –exp
■ configure to use them:
<configProtectedData>
<providers>
<add name="SampleProvider"
type="System.Configuration.RsaProtectedConfigurationProvider, …
keyContainerName="SampleKeys"
■ aspnet_regiis -pe "connectionStrings" -app
"/SampleApplication" -prov
"RsaProtectedConfigurationProvider"
■ sign application data?
■ RSACryptoServiceProvider RSAalg = new RSACryptoServiceProvider();
RSAalg.ImportParameters(Key);
return RSAalg.SignData(DataToSign,Index,Length, new
SHA1CryptoServiceProvider());
■ RSAalg.VerifyData(DataToVerify, SHA1CryptoServicePovider(), SignedData)
● Implement a secure site with ASP.NET.
○ This objective may include but is not limited to: secure communication by applying SSL certificates; salt
and hash passwords for storage; use HTML encoding to prevent cross-site scripting attacks (ANTI-XSS
Library); implement deferred validation and handle unvalidated requests, for example, form, querystring,
and URL; prevent SQL injection attacks by parameterizing queries; prevent cross-site request forgeries
(XSRF)
■ turn off validation on action [ValidateInput(false)] on property [AllowHtml]
■ deferred validation, means that a value is not validated until it is used
■ AntiXSS library
● Encoder.JavaScriptEncode, UrlEncode, HtmlEncode
● Sanitizer.GetSafeHtml, GetSafeHtmlFragment
■ <deployment retail="true" /> i Machine.Config
● turn off debug, trace and customErrors=”On”
Web.config Transformations
<connectionStrings>
<add name="MyDB"
connectionString="value for the deployed Web.config file"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
<system.web>
<customErrors defaultRedirect="GenericError.htm"
mode="RemoteOnly" xdt:Transform="Replace">
<error statusCode="500" redirect="InternalError.htm"/>
</customErrors>
</system.web>
xdt:Locator=(Condition(@name=’oldname’ or …
xdt:Transform=”Replace|Insert|InsertBefore(xpath)|InsertAfter|Remove|RemoveAll|RemoveAttributes”