building asp.net apps in windows azure name title microsoft corporation

26
Building ASP.NET Apps in Windows Azure Name Title Microsoft Corporation

Upload: gerald-ferguson

Post on 30-Dec-2015

235 views

Category:

Documents


0 download

TRANSCRIPT

Building ASP.NET Apps in Windows AzureNameTitleMicrosoft Corporation

Agenda

ASP.NET In Windows Azure Web Forms & MVCAJAX & Stateless Web RolesSession StateDNS

Advanced TechniquesFull IISMulti-tenancyWeb Deploy

ChallengesFile Upload

ASP.NET in Windows Azure

Web Forms and MVC

Windows Azure Tools for Visual Studio pre-defined role templatesASP.NET WebForms RoleASP.NET MVC 3 Role

What’s Different?

Statelessness

Load balancer round-robins requests in multi instance roles

Follow web farm best practicesDo not store state on individual instances Do not assume subsequent requests will hit the same instanceDon’t forget things like dynamically generated images loaded by a page

AJAX and Windows Azure

Client side calls may not return to the same instance the original page came from

AJAX calls must be statelessDon’t generate a page and leave state on the server to call via AJAX later

All instances require the same MachineKey for ViewState hashingFabric uses same machine key for all instances in a role

Windows Azure Session StateWindows Azure Load Balancer uses round-robin allocation. Session state must persist to client or storage on every request

LB

session[“foo”] = 1; session[“foo”] = 2;

What is the value of session[“foo”]?

SQL Azure

Windows Azure Storage

Solving Session State

Persist to Storage via Session State ProviderWindows Azure CachingSQL AzureWindows Azure StorageCustom

Persist to ClientUse cookies

Don’t forget ASP.NET MVC TempData relies on Session State provider by default

Windows Azure CachingUsing Windows Azure Caching as the session store

In-memory, distributed cache

Based on Windows Server Caching

Microsoft.Web.DistributedCache assembly found in the SDK

Enable ASP.NET 4 Session Compression

AppFabric Caching Caching

Caching Session StateSession state stored using Windows Azure Caching and an out-of-the-box session state provider

LB

session[“foo”] = 1; session[“foo”] = 2;

What is the value of session[“foo”]?

SQL Server Session State

Use SQL Azure as backing storeRound trip to database twice per requestRead at request startWrite at request end

Enable ASP.NET 4 Session CompressionScale out across multiple DBsUse session state partitioninghttp://bit.ly/scale-session

SQL Azure is competitive on cost basis

SQL Azure Session StateSession state stored using SQL Server Session State Provider and session state partitioning

LB

session[“foo”] = 1; session[“foo”] = 2;

What is the value of session[“foo”]?

SQL Azure 3 x 1GB

Databases

Resolve partition

Windows Azure Storage Providers Sample ASP.NET Providers

(Session, Membership, Role etc…)

Sample Codehttp://code.msdn.microsoft.com/windowsazuresamples

Uses Blob + Table Storage

Several storage transactions per request

Enable ASP.NET 4 Session Compression

Sample Provider should be treated as a starting point only.

Cookies

Serialize and Encrypt state into cookiePossible to implement as Session State ProviderCookies add significant performance overheadCookies sent with every request to domainUse alternative host header to serve images, etc.http://www.myweb.comhttp://images.myweb.com Use Windows Azure Storage for static content

DNS

All services get a *.cloudapp.net addressmyservicename.cloudapp.netTTL is 10 seconds

Standard approach is to CNAME to *.cloudapp.netRequires two DNS lookupsLimited caching due to low TTL

Use A records to point domain root

to your app.Must not delete your role or your IP address will change.

IP Address for deployment is fixed for lifetime of that slot

If you need to plan to delete a servicee.g. Because you need to change external endpoints

High Performance DNS ApproachCreate service, deploy to staging slot

Resolve IP for yourapp.cloudapp.net

Create A Record forwww.yourapp.comyourapp.com

1Lower TTL of A Records… wait a while…

2Create new service, get new IP, re-point A Records

3Delete old service

Advanced Techniques

Full IIS

You can choose to deploy to Full IIS; no longer using required to use Hosted Web Core (HWC)Differences:In Full IIS, the RoleEntryPoint runs under WaIISHost.exe while the web site runs under the normal IIS w3wp.exe process.

Support for running multiple websites

Load any IIS module

Makes migrating existing IIS-based applications a lot easier

Multi-TenancySaaS Applications often need to serve multiple tenants out of a single service deployment

LB

tenant1.saasservice.com tenant2.saasservice.com

SQL Azure 1 DB

per Tenant

resolve tenant by examining host header

Web RolesShared by all Tenants

Web DeployIIS Web Deployment Tool

Simplifies the migration, management, and deployment of IIS Web servers, Web applications, and Web sites

Perform web deploy using standard IIS7 publishing from Visual Studio

Will not require you to deploy an entire package

Warning: use for development purposes only

Common Challenges

File UploadASP.NET File Upload Control uses ASP.NET temporary directory to buffer filesTemp path cannot be changed to Local Resource or Windows Azure Drive

Windows Azure Compute roles have 100MB of root disk space

Problems ariseUploading large files (~100MB)

Multiple users uploading concurrently

10 users uploading 10MB files

File Upload SolutionsUpload direct to Blob storage using SilverlightProvide a Shared Access Signature to Silverlight controlUpload blocks direct to storage http://bit.ly/sl-blob

Use 3rd Party ControlImplement a custom IHttpHandler to receive file and buffer to disk

Takeaways

ASP.NET In Windows Azure

Advanced Techniques

Challenges

Broad support for ASP.NET Features

Must understand and architect for scale out

SaaS Applications usingVirtual Path Providers and Host header checking

© 2011 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to

be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.