Search This Blog

Wednesday, November 17, 2010

Upgrade Domains and Fault Domains in Windows Azure

Hi Friends,

Check the link below

http://blog.toddysm.com/2010/04/upgrade-domains-and-fault-domains-in-windows-azure.html

Affinity Groups in Windows Azure–How Those Work?

Affinity Groups is an interesting concept that Windows Azure introduced a while ago but it seems that people are confused how it works. Here is a short explanation how you can benefit from the Affinity Groups, and things that you need to be aware of when you use them.

Benefits of Using Affinity Group


As the name suggests Affinity Groups are intended to group dependant Windows Azure services, and deploy those in one place if possible. This can have several benefits among which are:

  • Performance – If your services are dependant on each other it is good if those are co-located, so that transactions between them are executed faster. The best option is if the network hops between your hosted services are minimized as much as possible
  • Lowering your bill – As you may already know bandwidth within the data center is free of charge (you are still charged for transactions though). Currently it is possible to co-locate your services if you choose the same sub-region and using Affinity Group is just another way to do that

How Affinity Groups Work?

Although the Affinity Groups give you the benefits outlined above, here are few things you need to be aware of when using them:


  • Specifying the same Affinity Group for two or more hosted services tells Windows Azure to optimize the deployment of those services and locate them closer to each other. Windows Azure makes best effort in this optimization
  • Specifying the same Affinity Group for hosted service and storage account means that those two will be co-located in the same data center. Right now this is equivalent to selecting the same sub-region for both

In essence Affinity Groups gives you small advantage over the use of sub-regions – it instructs Windows Azure to make an effort to deploy your hosted services and optimize their location.

 

Note (June 22nd 2010): I’ve done some edits to this post to unify the terminology with Windows Azure one, and clarify the billing benefit:

  1. Initially I wrote that transactions within data center are free of charge, which is not completely true. What I meant is that bandwidth is free of charge however you are still charged for transactions 
  2. Although I used “region” throughout the post I meant “sub-region” (for example US-North Central). In this context you should also consider “sub-region” and “data center” as interchangeable terms
  3. Choosing sub-region guarantees you that your service will be deployed in the selected sub-region. Choosing Affinity Group instructs Windows Azure Fabric to make a best effort to optimize the deployment of your services

Hope those clarifications are not distracting you from the main purpose of the post – to explain what the Affinity Groups can be used for.


Reference :
http://blog.toddysm.com/2010/06/affinity-groups-in-windows-azurehow-those-work.html

Tuesday, November 16, 2010

Did You Forget Your Windows Azure Demo Deployment Running? Graybox can help you!

Windows Azure as any other cloud platform is very convenient for doing demos or quick tests without the hassle of procuring hardware and installing bunch of software. However what happens quite often is that people forget their Windows Azure demo deployments running, and this can cost them money (a lot sometimes).

Recently I bumped into a handy tool called Graybox. What it does it to regularly check your Windows Azure subscription, and notify you about your deployments.

Installing Graybox

You can download Graybox from here. Just unzip it in a local folder and that is it. The tool has no installer and application icon.

Configuring Graybox

To use Graybox you need two things:

  • Windows Azure Subscription ID
  • and Windows Azure Management API Certificate Thumbprint – keep in mind that you need to have the certificate imported on the machine where Graybox will be running as well as uploaded it into Windows Azure through the Windows Azure Developer Portal

The configuration is quite simple – you need to edit the Graybox.exe.config file, which is simple XML file, and add your subscription ID and management API thumbprint as follows:

<add key="SubscriptionId" value="[SUBSCRIPTION_ID]"/>

<add key="CertificateThumbprint" value="[API_THUMBPRINT]"/>

Optionally you can change the refresh rate using RefreshTimerIntervalInMinutes configuration setting:

<add key="RefreshTimerIntervalInMinutes" value="10"/>

Using Graybox to Receive Notifications About Forgotten Windows Azure Deployments

Once you have Graybox configured you can start it by double-clicking on Graybox.exe. I will suggest you add the Graybox executable to All Programs –> Startup menu in order to have it started every time you start Windows. Once started it reminds resident in memory, and you can access its functionality through the tray icon:

graybox-system-tray

Right-clicking on Graybox’ tray icon shows you the actions menu:

graybox-menus
As you can see on the picture above deployments are shown in the following format:

 

[hosted_service_name], [deployment_label] ([status] on [environment])

For example: toddysm-playground, test (Suspended on Production)

Thus it is easy to differentiate between the different deployments. You have the option to “kill” particular deployment (this means to suspend it if it is running AND delete it or just delete it if the deployment is suspended) or to “kill” all deployments.

If you have forgotten that you have deployments Graybox will pop a message above the system tray every couple of minutes to remind you that you have something running:

graybox-alert

The refresh rate is the one you configured in Graybox.exe.config configuration file.

Graybox Limitations

There are two things you should keep in mind when planning to use Graybox:

  • Graybox can track deployments in only one subscription; if you own more than one Windows Azure subscription you will not be able to see all your deployments
  • In addition Graybox requires .NET 4.0, and will not work with earlier versions of .NET framework

More Information About Graybox

Using Graybox is free because you don’t pay for accessing the Windows Azure Management APIs.

You can get additional information on their Codeplex page.

Remote Desktop Connection to Windows Azure Instance

In this morning’s PDC2010 keynote Bob Muglia revealed the secret, and I would like to start with my favorite feature – establish Remote Desktop connection to any Windows Azure instance. Here is the step-by-step guide how to enable the feature, and how to use it.


Configuring Windows Azure Deployment for RDP

The first thing I did is to create new basic Cloud Project in Visual Studio. I called it Hello RDP. Nothing new here. I modified the Default.aspx page just to make it say: “Hello, RDP!”.

Here are the steps (quite simple) that you need to go through to enable Remote Desktop in your deployment:

  1. In Visual Studio right-click on the Cloud Project (Hello RDP in my case) and select Publish. You will be presented with the Deploy Windows Azure project dialog below:

    image

    I have selected the Create Service Package Only option but you have the choice to deploy from Visual Studio to the cloud directly if you want.
  2. Next click on the link Configure Remote Desktop connection above the OK button. You will see the Remote Desktop Configuration dialog where you can select the certificate you want to use to encrypt the credentials as well as the actual credentials you want to use to login to the instance and the expiration date for the password.

    image
    In the Certificates drop down you can select a certificate from your local cert store or create a new one that will be sored locally. After you fill in all the information click on the OK button in the current dialog as well as in the deployment dialog.

    Your package will be created on the local hard drive.

    Note: If you do not have Hosted Service created and/or if you don’t have the certificate already uploaded through the Windows Azure Portal you should create the package locally and deploy it through the Portal. See next section for more details.

Configuring the Windows Azure Hosted Service

In the current implementation (as of PDC10) you need to create hosted service and upload the certificate before you do the deployment. There may be some changes for the official release of the new UI in order to make it more streamlined. Here is the current workflow:

  1. Load the Windows Azure Portal and click on Compute, Storage & CDN in the navigation area

    image
  2. Click on the Compute Services node in the tree. In the grid you will see your subscription (or subscriptions if you have more than one)

    image
  3. Click on the New Hosted Service button, and you will get the dialog to fill in Hosted Service and Deployment information

    image

    In the new Windows Azure Portal UI we combined the creation of Hosted Service and the Deployment in one step. However for RDP you should choose the “Do not deploy” option because you will receive error if you don’t have the certificate uploaded.
  4. When you fill in all the information click the OK button and you will see your Hosted Service appear below your subscription.

    image
  5. Expand the Compute Services node in the tree and select the Service Certificates node

    image
  6. Click on Add Certificate to open the Upload Certificate dialog. Select the same certificate that you selected in the Visual Studio dialog when configuring your package, and click the Create button.

    Note: Make sure you select the right Hosted Service in the Target Hosted Service dialog

    image
  7. After it is uploaded you will see your certificate in the grid

    image
  8. Go back to the Compute Services view and click on New Production Deployment (or New Staging Deployment if you want to deploy to staging). Create a new Deployment dialog will appear where you can select the package and the configuration file you created in visual studio above.

    image
  9. After clicking OK you will see new line item in the grid that represents your deployment. In addition you will receive frequent updates what is happening with the deployment, and it will expand once the roles and instances are spun up. Really cute – isn’t it? Winking smile We refresh the status every 10 seconds.

    image
    Now, you just need to wait until your deployment is complete.

Connecting to the Windows Azure Instance

Once the deployment is complete the instances will be in Ready state, and when you select any one of them the Remote Desktop Connect button in the ribbon will light up.

image

 

When you click the Connect button you will be asked to download RDP file from the Windows Azure Portal (Note: Silverlight will also present you with security warning the first time you click on the Remote Access Connect button; you can select the checkbox in the warning if you don’t want to be warned in the future). You can select Open in the prompt for downloading the RDP file and the connection to the Windows Azure Instance will be established. Optionally you can save the RDP file locally for future use.


 

image

 

Voila! You are in!

 

image

 

Finally, it is highly recommended that you turn off Remote Desktop access to your Windows Azure instances when you don’t need it in order to avoid security risks. You can do this very easily from the Portal – just select the Role row, and uncheck the Remote Access Enabled checkbox:

image

 

Final Notes and Disclaimers About the Remote Desktop Feature


Couple of things I would like to mention at the end:

  • First, the Remote Desktop feature is scheduled to be released at the end of the year, which means we are still working on it and there may be some changes in the workflow
  • And second, the new Windows Azure Portal UI is also scheduled to release at the end of November and there may be some changes in the UI also. I have used the environment we use for the PDC demos to make the screenshots above, and if you are attending the conference you will see the same UI in the hands-on labs

I will try to update this blog post with any changes we make between PDC and the final release.

Hope you enjoy the new features in Windows Azure, and as always your feedback is highly appreciated.


Reference: http://blog.toddysm.com/2010/10/remote-desktop-connection-to-windows-azure-instance.html

PDC2010 – Building Engaging Apps with Windows Azure Marketplace DataMarket Session

Showing off different and Interesting integration scenarios with DataMarket

  • Facebook application that integrates with a Data.Gov DataSets
  • Usage of Windows Azure DataMarket Portal to explore the DataSets and also to show off the Tableau application to consume the DataSet from DataMarket

Integration Scenarios 

  • Choices:
    • Specific dataset versus generic
      • Influences the choice over the type of client technology to be used
        • WebRequest – need to parse the XML by hand
        • WCF Data Services client – ODATA client
        • DataMarket service proxy classes
    • Which DataMarket Account?

Building a simple Windows Phone 7 application

  • App that uses two DataMarket DataSets, one about weather forecast and another about the population density
    1. Choose the DataMarket DataSet
    2. Explore the DataSet
    3. Test the DataMarket DataSet
    4. Choose the Type of Integration to use
      • In this case the WebRequest is the one that is chosen
    5. Copy the Query URL
    6. Pass the Account Id and Account Key to the WebRequest
    7. Perform the Request
    8. Analyze the Response and Extract the XML elements that you need from the response.
  • Each content provider deliver a set of help resources like samples, and documentation about the respective DataSet that are accessible on the DataSets Page
  • Notes:
    • Can be built using WebRequest directly
    • Consider service-side
      • Filtering – Filter only what you need and cache your results on the server to lower the bandwidth
      • Projections – Do Projections on the Server-side in order to send only the elements that are interesting and needed by the client, reducing the used bandwidth

Next Steps:

Author : NunoGodinho

Understanding Windows Azure Connect – PDC10 Session Review

Introducing Windows Azure Connect

  • Secure network connectivity between on-premises and cloud
    • Supports standard IP protocols (TCP, UDP)
  • Example use cases:
    • Enterprise app migrated to Windows Azure that requires access to on-premise SQL Server
    • Windows Azure app domain-joined to corporate Active Directory
    • Remote administration and troubleshooting of Windows Azure roles
  • Simple setup and management

Roadmap

  • CTP release by end of 2010
    • Support connect from Azure to non-Azure resources
      • Supports Windows Server 2008 R2, Windows Server 2008, Windows 7, Windows Vista SP1, and up
  • Future releases
    • Enable connectivity using existing on-premises VPN devices

Closer Look

  • Three steps to setup Windows Azure connect
    1. Enable Windows Azure (WA) roles for External connectivity via service Model
      • Select only the roles that should be enabled for external onnectivity
    2. Enable local computers for connectivity by installing WA Connect Agent
    3. Configure/Manage your network policy that defines which Azure roles and which Azure computers can communicate.
      • defined using the Connect Portal
  • After the Configuration/Management of the Network Polity, Azure Connect automatically setups secure IP-level network between connected role instances and local computers
    • Tunnel firewall/NAT/s through hosted relay service
    • Secured via end-to-end IPSec
    • DNS name resolution

Windows Azure Service Deployment

  • To use Connect for a Windows Azure Service, enable one or more of its Roles
    • For Web & Worker Roles, include the connect plug-in as part of the Service Model (using .csdef file)
    • For VM Roles, install the connect agent in VHD image using Connect VM Install package
    • Connect agent will automatically be deployed for each new role instance that starts up
  • Connect agent configuration is managed through the ServiceConfiguration (.cscfg file)
    • One one configuration setting is required
      • ActivationToken
        • Unique per-subscription token, accessed from Admin UI
    • Several Optional settings for managing AD domain-join and service availability

Deployment

On-Premise

    • Local computers are enabled for connectivity by installing & activating the Connect Agent. It can be retrieved from:
      • Web-based installation link
        • Retrieved from the Admin Portal
        • Contains per-subscription activation token embedded in the url
      • Standalone install package
        • Retrieved from the Admin Portal
        • Enabled installation using existing software distribution tools
    • Connect agent tray icon & client UI, enables us to:
      • View activation state & connectivity status
      • Refresh network policy
    • Connect agent automatically manages network connectivity, by:
      • Setting up a virtual network adapter
      • “Auto-connecting” to Connect relay service as needed
      • Configuring IPSec policy based on network policy
      • Enabling DNS name resolution
      • Automatically syncing latest network policies

Management of Network Policy

    • Connect network policy managed through Windows Azure admin portal
      • Managed on a per-subscription basis
    • Local Computers are organized into groups
      • Eg. “SQL Server Group”, “Laptops Group”, …
      • A computer can only belong to a single group at a time
      • Newly activated computers aren’t assigned to any group
    • Windows Azure roles can be connected to groups
      • Enabled network connectivity between all Role instances (VMs) and local computer in the Group
      • Windows Azure connect doesn’t connect to other Windows Azure Roles
    • Groups can be connected to other Groups
      • Enabled network connectivity between computers in each group
      • A group can be ‘interconnected’ – enables connectivity within the group
      • Useful for ad-hoc & roaming scenarios
        • Eg. your laptop having a secure connection back to a server that resides inside the corp net

Network Behavior

  • Connect resources (Windows Azure role instances and external machines) have secure IP-level network connectivity
    • Regardless of physical network topology (Firewall / NATs) as long as they support outbound HTTPs access to Connect Relay service
  • Each connected machine has a routable IPv6 address
    • Connect agent sets up the virtual network address
    • No changes to existing networks
  • Communication between resources is secured via end-to-end certificate-based IPSec
    • Scoped to Connect Virtual network
    • Automated management of IPSec certificates
  • DNS name resolution for connected resources based on machine names
    • Both directions are supported (Windows Azure to Local Computer or vice-versa)

Active Directory Domain Join

  • Connect plug-in support domain-join of Windows Azure roles to on-premise Active Directory
  • Eg. Scenarios:
    • Log into Windows Azure using Domain Accounts
    • Connect to on-premise SQL Server using Windows Integrated Authentication
    • Migrate LOB apps to cloud that assume domain-join environment
  • Process:
    1. Install Connect agent on DC/DNS servers
      • Recommendation: create a dedicated site in the case of multiple DC environment
    2. Configure Connect plug-in to automatically join Windows Azure role instances to Active Directory
      • Specify credentials used for domain-join operation
      • Specify the target OU for Windows Azure roles
      • Specify the list of domain users / groups to add to the local administrators group
    3. Configure the network policy to enable connectivity between Windows Azure roles and DC/DNS Servers
    • Note: New Windows Azure role instances will automatically be domain-joined

Finally the recap of Windows Azure Connect

  • Enables secure network connectivity between Windows Azure and on-premise resources
  • Simple to Setup & Manage
    • Enabled Windows Azure Roles using connect plug-in
    • Install Connect agent on local computers
    • Configure network policy
  • Useful Scenarios:
    • Remote administration & troubleshooting
    • Windows Azure Apps Access to on-premise Servers
    • Domain-join Windows Azure roles
Reference : http://msmvps.com/blogs/nunogodinho/archive/2010/11/15/understanding-windows-azure-connect-pdc10-session-review.aspx
By: Anthony Chavez – Director @ Windows Azure Networking Group
Author : NunoGodinho

Sunday, November 14, 2010

Watch or Download PDC 10 release Sessions

Hi Friends,

Watch the Sessions at the link given below

You can also download using PDC10 Downloader
http://blogs.msdn.com/b/mark/archive/2010/11/03/pdc10-downloader.aspx

New features per Windows Azure Platform released on 28th Oct 2010

Summary of New 'Windows Azure Platform' features announced at PDC10 Oct. 28th-29th 2010

So, great news at PDC10!. Here I make a summary about new features per Windows Azure Platform pillar (Windows Azure, SQL Azure, AppFabric):

Windows Azure
New Windows Azure Features
State
Description
VM role
Beta in 2010
Eases the migration of existing Windows Server applications to Windows Azure
Extra Small VM
Beta in 2010
For small apps or PoCs
Virtual Network

‘Windows Azure Connect’ is 1st wave
(aka. 'Project Sydney')
CTP in 2010
Windows Azure Connect (previously known as “Project Sydney”) enables a simple and easy-to-manage mechanism to set up IP-based network connectivity between on-premises and Windows Azure resources.
Remote Desktop
RTW in 2010
Remote Admin and monitoring
Admin Mode
(Elevated privileges)
RTW in 2010
For small changes such as configuring Internet Information Service (IIS) or installing a Microsoft Software Installer (MSI), Microsoft recommends using the Elevated Privileges admin access feature. This approach is best suited for small changes and enables the developer to retain automated service management at the Guest OS and the application level.
Full IIS Support
RTW in 2010
Enables multiple IIS sites per Web role and the ability to install IIS modules
Multiple WA account  Admins
RTW in 2010
Multiple Windows Live IDs admins
CDN Dynamic Content Caching
In 2011
Windows Azure CDN can be configured to cache content returned from a Windows Azure application
CDN SSL
In 2011
Deliver content via encrypted channels with SSL/TLS
New Windows Azure portal
In 2010
Redesigned Microsoft Silverlight-based Windows Azure portal
SQL Azure
New SQL Azure Features
State
Description
SQL Azure Reporting
CTP
Developers can author reports using familiar SQL Server  Reporting Services tools and then easily provision and deploy reports into the cloud.
SQL Azure Data Sync
CTP 2
Enables to synchronize SQL Azure databases across datacenters as well as with on-premises SQL Server.
(Entire databases or specific tables)

Database manager for SQL Azure (aka. Houston)
RTW in 2010
New lightweight, web-based database management and querying capability for SQL Azure databases. I was formerly referred to as “Project Houston”, and allows customers to have a streamlined experience within the web browser without having to download any tools.
Windows Azure App Fabric 
New AppFabric Building Blocks
State
Description
AppFabric Cache
CTP at PDC
RTW in 2011
Distributed, in-memory application cache, like Windows Server AppFabric Cache (Velocity) but in windows Azure.
Durable messaging in Service Bus (CTP at PDC)
CTP at PDC
RTW in 2011
Higher enterprise reliability, giving improved delivery assurance for messages to third-parties or mobile devices
Integration (CTP in CY11) Common BizTalk Server integration capabilities
CTP in CY11
Pipeline, transforms, adapters, BAM and rules, etc.
Composition Model and Tools
CTP in CY11
Will help developers compose applications on the Windows Azure Platform with extensions to the .NET Framework and tie them all together through a new Microsoft Visual Studio-based designer experience.

Composition Service
CTP in CY11
Allows developers to take the Composition Model and automate the deployment, configuration, control, monitoring, troubleshooting, reporting and optimization of an application without the usual manual steps.

 Other WA related new features  
Other New Features
State
Description
TFS on Windows Azure
CTP In 2011
Visual Studio Team Foundation Server in Windows Azure
Windows Azure MarketPlace
CTP In 2011
A single online marketplace for developers and IT professionals to share, find, buy and sell building block components, training, services, needed to build complete and compelling Windows Azure applications
DataMarket
RTW in 2011
Formerly code-named “Dallas”.  It is really part of the MarketPlace
Reference : http://blogs.msdn.com/b/cesardelatorre/archive/2010/10/28/new-windows-azure-platform-features-announced-at-pdc10-oct-28th-29th-2010.aspx

Monday, December 15, 2008

ASP.Net Coding & Performance Tips

ASP.net Tips

from http://www.codersource.net/asp_net_simple_tips.html


1.Smart navigation

Smart navigation is a little-known Internet Explorer feature that enables the individual controls on your Web forms to maintain focus between postback, as well as allows you to suppress that flicker that occurs as you load the new page.
To turn on this little-known feature, simply set the smartNavigation property of your ASPX page to True. You can also apply the property to all project pages, by adding the tag to the following location within your Web.config file:

<--configuration system.web pages smartNavigation="true"/ /system.web /configuration -->

Note that smart navigation works on only Internet Explorer 5 and above; however, ASP.NET will automatically detect this and serve up the ?smart? code only if the target browser supports it.

Also,I'd personally advise that you test it against any third-party menu controls or scripts you may have running: it is prone to falling over on particularly advanced pages.


2.Stopping Your User from Right-Clicking


Want to prevent your user from performing any of the other commands available by right-clicking on a Web page in Internet Explorer? It?s not foolproof, but this neat little HTML edit usually does the trick.

Just alter the opening tag of your HTML to the following:

BODY oncontextmenu="return false">

When the menu is requested, the oncontextmenu event runs, and we instantly cancel it using JavaScript. This is especially potent as a method for stopping the user from viewing your source, when used in conjunction with a menu-less browser window. Great stuff!

3.Creating Images Dynamically

Ask any ASP developer who has ever tried to dynamically create his own images and he?ll tell you it?s a nightmare. In fact, it?s more than a nightmare. It?s practically hell. The only true solution? Reverting to an expensive, dodgy, third-party control to do the work for you.

With ASP.NET, however, you can develop your own dynamic images with ease. Simply create an image object and use the new GDI+ features to add objects to that image, such as text, rectangles, and ellipses. After that, you can simply stream straight back down to the client.

But covering the graphics features in depth would require at least another two books, and, unfortunately, we don?t have that much room. So, I?m going to share a sample that demonstrates creating a small ?Drawing? button, alongside a little blue-and-yellow bullet point.It?s the sort of personalized graphic you?ll find on sites such as Amazon.com.

Here's the code:

Bitmap objBitmap = new Bitmap(120, 30);
Graphics objGraphics = Graphics.FromImage(objBitmap);
objGraphics.FillRectangle(new SolidBrush(Color.LightBlue), 0, 0, 120, 30);
objGraphics.FillEllipse(new SolidBrush(Color.Blue), 3, 9, 10, 10);
objGraphics.FillEllipse(new SolidBrush(Color.Yellow), 4, 10, 8, 8);
objGraphics.DrawString("Drawing", new Font("Tahoma", 8), new SolidBrush(Color.Green), 16, 8);
Response.Clear();
Response.ContentType = "image/jpeg";
objBitmap.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
objGraphics.Dispose();
objBitmap.Dispose();


You can put it inside any event you want.

4.Clear All The Textbox Values (Reset Function)

In Classic ASP, to clear all the textboxes in a form, to start over, we just had to use a simple html 'Reset' button in the form. Sometimes that works in ASP.Net;sometimes it doesn't.

Here are a couple of ways to do this, iterating through the ASP.Net TextBox controls in a form --
Just create a Reset type subroutine - in that routine, use the following code:
in C# - it would be:

Control myForm = Page.FindControl("Form1");
foreach (Control ctl in myForm.Controls)
if(ctl.GetType().ToString().Equals("System.Web.UI.WebControls.TextBox"))
((TextBox)ctl).Text = "";

This will clear EVERYTHING from the textboxes - even if you had them pre-populated with data. A VERY simple way to just reset it to the condition at Page_Load time, just do this in the Reset SubRoutine:

Server.Transfer("YourPageName.aspx")

5.Pressing Enter key

Sometimes, you will notice, that, in an ASP.Net form, depending on the circumstances, pressing the 'Enter' key to submit the form does not work.

To force this to happen for a particular button on your page, just put this in the Page_Load routine:

Page.RegisterHiddenField("__EVENTTARGET", "button1")

Then, change 'button1' to the ID of your particular button. Understand, of course, if your cursor is inside of a MultiLine textbox, the default action of the enter key is to create a new line in the textbox, so, if this basically works anywhere outside of that scenario.
6.ASP.Net Server Controls Not Showing on pages

It's possible that ASP.Net is not registered correctly on your system.Try running aspnet_regiis from the command prompt
.

Here's the default location:

C:\WINNT\Microsoft.NET\Framework\<>\aspnet_regiis.exe -i

Windows Server 2003, you must use aspnet_regiis -i -enable. This is because of the "Web Service Extensions" feature in IIS 6

7.Where To Store Database Connection

Let's say you have a database connection (or several) that you will be using over and over. Yes, you can manually copy/type it in on every ASP.Net page - BUT - an easier way is to store it in the Web.Config file (formerly config.web) and then refer to it in the code.

In Web.Config, you would add a key to the AppSettings Section:

appSettings>
add key="MyDBConnection" value="server=YourServer;uid=Username;pwd=Password;database=DBName" />


for OleDb - use Absolute Path - Not Server.MapPath:
add key="NWOleDB" value= "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\data\northwind.mdb;" />

Then, in your ASP.Net application - just refer to it like this:

SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings("MyDBConnection"));


Sunday, December 14, 2008

Quick Tips For ASP.Net

Quick Tips For ASP.Net

from http://simpable.com/code/quick-tips-for-asp-net-part-one/

written by Scott Watermasysk on Thursday, February 15 2007

Just about everyone has been to a session on ASP.Net best practices, read a book or 10 on the subject, and possibly even a couple of blog posts or MSDN articles. This post is NOT one of them. It is simply a quick list of tips and suggestions for making your ASP.Net application a little better.

I jotted down the tips below over the course of the morning. It is by no means exhaustive and I hope to publish another set of tips or two shortly. If you have any other suggestions/tips, please list them below. If you are not the kind of person who likes to comment on a blog, please drop me a line at scottwater@gmail.com. I will either add them below or create another post and list them. I am also working on a set of caching tips, so if you have any of them, there will be a specific post related to caching.

Tip: Do not use the AutoPostBack attribute on the DropDownList control to simply redirect to another page.

There are probably cases when this might make sense, but for the most part it is overkill. Using the autopostback for a redirect requires extra roundtrip to the server. First the autopostback returns to the server and processes everything up to the event handling the postback. Next a Response.Redirect is issued which goes back to the client requesting the client use another page. So you end up with two separate requests + processing just to get a user to another page.

Using the onchange event of the select element, we can do this all on the client. In the sample below, I am simply redirecting to the current page with an updated querystring element. Your logic will vary, but in the case below, I am avoiding the zero index.

0) { window.location = window.location.pathname + '?t=' + this[this.selectedIndex].value;}" />

Tip: Never use the ASP.Net Label control.

Ever is a strong word, but except for some quick and dirty style hacks you should never ever use this control. Any text is rendered inside a span control which is usually unnecessary and complicates any CSS styling you may be trying to use. In most cases, you can replace the Label with a Literal and achieve the same results.

Tip: Use the ASP.Net Repeater instead of DataList, DataGrid, and DataView controls

The Repeater is the single most powerful control shipped in ASP.NET. It is versatile and lightweight. There are times (especially prototyping) when the other databound controls make sense to use, but they generate a lot of extra markup and generally complicate the page with all of their events and styling. Using the Repeater, you may write a little more code up front, but you will be rewarded in the long run.

Tip: Understand how to effectively use caching.

By now, most ASP.NET developers know about the Cache. Most examples show the virtue of caching for hours at a time. Very little data that is worth the effort to display on a web page requires caching for this long. The main reasons for caching are performance related. Memory in ASP.NET is still a very limited resource. Do not waste it by caching anything more than a couple of minutes unless it is very expensive to regenerate.

Tip: Always set a memory threshold for your AppPool.

A related tip would be to first understand the total memory available on your box: how many sites are there, is SQL running locally? Is there anything else on this box which will consistently use Memory?

In most cases, you should never set the available memory for an AppPool above 800mb's unless you can also set the 3/gb switch (then you can use about 1200mb). Allowing memory to go unchecked or set about 800mb can bring even a moderately sized site to it's knees once too much memory is used.

Tip: Use AppOffline.htm for updates

If you are making any changes to files in your bin directory, always use the AppOffline.htm file. It is very likely that while you uploading (or copy & pasting) your updates, users will see an error message. It is much better to show them one that you purposely created and can explain the situation vs. the built in ASP.NET error pages (or even your own customError page). In addition, this will help prevent the locking .dll issue that is not supposed to exist anyway.

Tip: Always check Page.IsValid in your button's EventHandler.

Just because you are using ASP.Net validation controls, do not assume the page could not be submitted with invalid data.

Also, just because you hide a control, do not assume buttons/textboxes/etc on it are not submit-able. It is perfectly fine to hide a control that a user should not access, but with very little code (or using a third party tool) users can easily make an HttpPost with any data they choose.

Tip: When redirects are permanent, use a 301 status code.

This use to be a little more manual, but with ASP.NET 2.0, it is even easier:

Response.RedirectLocation = "http://site.com/newlink.aspx";
Response.End();

Tip: To create fully qualified URLs, use the new VirtualPath class.

string relativePath = "~/somefolder/test/123.aspx"
Uri newUri = new Uri(Request.Url, VirtualPathUtility.ToAbsolute(relativePath));

Again, please add any other suggestions below. I am looking forward to reading them.

Update: It looks like there is a case for using the Label control as an html label element (for accessibility). I was unaware of this functionality and will call it out better in another tip installment. Thanks Phil and Dusty!