Building ASP.NET Apps in Windows Azure

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

description

Building ASP.NET Apps in Windows Azure. Name Title Microsoft Corporation. Agenda. ASP.NET In Windows Azure Web Forms & MVC AJAX & Stateless Web Roles Session State DNS Advanced Techniques Full IIS Multi-tenancy Web Deploy Challenges File Upload. ASP.NET in Windows Azure. - PowerPoint PPT Presentation

Transcript of Building ASP.NET Apps in Windows Azure

Page 1: Building ASP.NET Apps in Windows Azure

Building ASP.NET Apps in Windows AzureNameTitleMicrosoft Corporation

Page 2: Building ASP.NET Apps in Windows Azure

Agenda

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

Advanced TechniquesFull IISMulti-tenancyWeb Deploy

ChallengesFile Upload

Page 3: Building ASP.NET Apps in Windows Azure

ASP.NET in Windows Azure

Page 4: Building ASP.NET Apps in Windows Azure

Web Forms and MVCWindows Azure Tools for Visual Studio pre-defined role templatesASP.NET WebForms RoleASP.NET MVC 3 Role

Page 5: Building ASP.NET Apps in Windows Azure

What’s Different?

Page 6: Building ASP.NET Apps in Windows Azure

StatelessnessLoad balancer round-robins requests in multi instance rolesFollow 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

Page 7: Building ASP.NET Apps in Windows Azure

AJAX and Windows AzureClient side calls may not return to the same instance the original page came fromAJAX 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

Page 8: Building ASP.NET Apps in Windows Azure

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

Page 9: Building ASP.NET Apps in Windows Azure

Solving Session StatePersist 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

Page 10: Building ASP.NET Apps in Windows Azure

Windows Azure CachingUsing Windows Azure Caching as the session storeIn-memory, distributed cacheBased on Windows Server CachingMicrosoft.Web.DistributedCache assembly found in the SDKEnable ASP.NET 4 Session Compression

Page 11: Building ASP.NET Apps in Windows Azure

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”]?

Page 12: Building ASP.NET Apps in Windows Azure

SQL Server Session StateUse 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

Page 13: Building ASP.NET Apps in Windows Azure

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

Page 14: Building ASP.NET Apps in Windows Azure

Windows Azure Storage Providers Sample ASP.NET Providers

(Session, Membership, Role etc…)Sample Codehttp://code.msdn.microsoft.com/windowsazuresamplesUses Blob + Table StorageSeveral storage transactions per requestEnable ASP.NET 4 Session Compression

Sample Provider should be treated as a starting point only.

Page 15: Building ASP.NET Apps in Windows Azure

CookiesSerialize 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

Page 16: Building ASP.NET Apps in Windows Azure

DNSAll 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

Page 17: Building ASP.NET Apps in Windows Azure

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 slotResolve IP for yourapp.cloudapp.netCreate A Record forwww.yourapp.comyourapp.com

1 Lower TTL of A Records… wait a while… 2 Create new

service, get new IP, re-point A Records

3 Delete old service

Page 18: Building ASP.NET Apps in Windows Azure

Advanced Techniques

Page 19: Building ASP.NET Apps in Windows Azure

Full IISYou 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 websitesLoad any IIS module

Makes migrating existing IIS-based applications a lot easier

Page 20: Building ASP.NET Apps in Windows Azure

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

Page 21: Building ASP.NET Apps in Windows Azure

Web DeployIIS Web Deployment ToolSimplifies the migration, management, and deployment of IIS Web servers, Web applications, and Web sitesPerform web deploy using standard IIS7 publishing from Visual StudioWill not require you to deploy an entire packageWarning: use for development purposes only

Page 22: Building ASP.NET Apps in Windows Azure

Common Challenges

Page 23: Building ASP.NET Apps in Windows Azure

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 concurrently10 users uploading 10MB files

Page 24: Building ASP.NET Apps in Windows Azure

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

Page 25: Building ASP.NET Apps in Windows Azure

Takeaways

ASP.NET In Windows Azure

Advanced Techniques

Challenges

Broad support for ASP.NET FeaturesMust understand and architect for scale out

SaaS Applications usingVirtual Path Providers and Host header checking

Page 26: Building ASP.NET Apps in Windows Azure

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