ASPHostDirectory Cheap ASP.NET 4 Hosting

Blog about .NET 4 Hosting and all its latest technology

ASPHostDirectory ASP.NET 4 Hosting :: URL Routing in ASP.NET 3.5 Webform

clock January 6, 2011 05:57 by author Darwin

URL Routing decouples the URL from a physical file on the disk, we can define routing rules to specify what URL maps to what physical files. ASP.NET Routing is not only for MVC and is independent library so ASP.NET Routing can be used in a traditional ASP.NET web forms.

First, add a reference to System.Web.Routing and make sure that web.config has UrlRoutingModule HTTP Module registered in httpModules section.

then, we create this class,

CustomRouteHandler.cs
//------------------------------------------------------
public class CustomRouteHandler : IRouteHandler
{
public CustomRouteHandler(string virtualPath)
{
this.VirtualPath = virtualPath;
}


public string VirtualPath { get; private set; }

public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
foreach (var paramUrl in requestContext.RouteData.Values)
{
requestContext.HttpContext.Items[paramUrl.Key] = paramUrl.Value;
}
var page = BuildManager.CreateInstanceFromVirtualPath(VirtualPath, typeof(Page)) as IHttpHandler;
return page;
}
}
//--------------------------------------------------
Then in Global.asax file and in Application_Start event, I will define my routing rules.

Global.asax
//----------------------------------------------
void Application_Start(object sender, EventArgs e)
{
RegisterRoutes(RouteTable.Routes);
}


private void RegisterRoutes(System.Web.Routing.RouteCollection routes)
{
routes.Clear();

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{resource}.aspx/{*pathInfo}");
routes.IgnoreRoute("{resource}.ashx/{*pathInfo}");

routes.Add("IndexPage", new Route("index/{page-num}", new CustomRouteHandler("~/Home/index.aspx")));
routes.Add("Index", new Route("index", new CustomRouteHandler("~/Home/index.aspx")));
routes.Add("ContactUs", new Route("contactus", new CustomRouteHandler("~/Home/contactus.aspx")));

}

The Route Data will be stored in HttpContext.Item (cache per request)
You can get the Route Data from HttpContext.Current.Items["name"] on the page.


What is so SPECIAL on ASPHostDirectory.com ASP.NET 4.0 Hosting?

We know that finding a cheap, reliable web host is not a simple task so we’ve put all the information you need in one place to help you make your decision. At ASPHostDirectory, we pride ourselves in our commitment to our customers and want to make sure they have all the details they need before making that big decision.

We will work tirelessly to provide a refreshing and friendly level of customer service. We believe in creativity, innovation, and a competitive spirit in all that we do. We are sound, honest company who feels that business is more than just the bottom line. We consider every business opportunity a chance to engage and interact with our customers and our community. Neither our clients nor our employees are a commodity. They are part of our family.

The followings are the top 10 reasons you should trust your online business and hosting needs to us:

- FREE domain for Life - ASPHostDirectory gives you your own free domain name for life with our Professional Hosting Plan and 3 free domains with any of Reseller Hosting Plan! There’s no need to panic about renewing your domain as ASPHostDirectory will automatically do this for you to ensure you never lose the all important identity of your site
- 99,9% Uptime Guarantee - ASPHostDirectory promises it’s customers 99.9% network uptime! We are so concerned about uptime that we set up our own company to monitor people’s uptime for them called ASPHostDirectory Uptime
- 24/7-based Support - We never fall asleep and we run a service that is opening 24/7 a year. Even everyone is on holiday during Easter or Christmast/New Year, we are always behind our desk serving our customers
- Customer Tailored Support - if you compare our hosting plans to others you will see that we are offering a much better deal in every aspect; performance, disk quotas, bandwidth allocation, databases, security, control panel features, e-mail services, real-time stats, and service
- Money Back Guarantee - ASPHostDirectory offers a ‘no questions asked’ money back guarantee with all our plans for any cancellations made within the first 30 days of ordering. Our cancellation policy is very simple - if you cancel your account within 30 days of first signing up we will provide you with a full refund
- Experts in ASP.NET 4.0 Hosting - Given the scale of our environment, we have recruited and developed some of the best talent in the hosting technology that you are using. Our team is strong because of the experience and talents of the individuals who make up ASPHostDirectory
- Daily Backup Service - We realise that your website is very important to your business and hence, we never ever forget to create a daily backup. Your database and website are backup every night into a permanent remote tape drive to ensure that they are always safe and secure. The backup is always ready and available anytime you need it
- Easy Site Administration - With our powerful control panel, you can always administer most of your site features easily without even needing to contact for our Support Team. Additionally, you can also install more than 100 FREE applications directly via our Control  Panel in 1 minute!

Happy Hosting!



ASPHostDirectory Visual Studio 2010 Hosting :: How to Solve Error CS0006, CS0009 in Visual Studio 2008

clock December 16, 2010 07:16 by author Darwin

Error Message:

CS0006: Metadata file 'C:\WINDOWS\assembly\GAC_32\System.EnterpriseServices\2.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.dll' could not be found


How to Solve it?

1. check whether "System.EnterpriseServices.dll" file actually exists at that folder or not. You cannot navigate to the GAC_32 folder using windows explorer. You have to use command line to go there. From start menu, select 'Run' > type 'cmd' press enter. then directly go there:

cd C:\WINDOWS\assembly\GAC_32\System.EnterpriseServices\2.0.0.0__b03f5f7f11d50a3a

2. press enter. From here you have to copy the file to the desired location. Use this command:

copy System.EnterpriseServices.dll C:\WINDOWS\assembly\GAC_32\System.EnterpriseServices\2.0.0.0__b03f5f7f11d50a3a

3. Now try to run that web project from visual studio, and it should work. If it doesnt work, and gives you another error: CS0009 compile error, then you have to copy all the files to that folder. First navigate to that source folder:

cd C:\Windows\Microsoft.NET\Framework\v2.0.50727

4. press enter. Then use this command to copy all DLLs:

copy *.dll C:\WINDOWS\assembly\GAC_32\System.EnterpriseServices\2.0.0.0__b03f5f7f11d50a3a

You dont need to overwrite any file that already exists at the destination folder. This should solve CS0009 error.


What is so SPECIAL on ASPHostDirectory.com Visual Studio 2010 Hosting?

We know that finding a cheap, reliable web host is not a simple task so we’ve put all the information you need in one place to help you make your decision. At ASPHostDirectory, we pride ourselves in our commitment to our customers and want to make sure they have all the details they need before making that big decision.

We will work tirelessly to provide a refreshing and friendly level of customer service. We believe in creativity, innovation, and a competitive spirit in all that we do. We are sound, honest company who feels that business is more than just the bottom line. We consider every business opportunity a chance to engage and interact with our customers and our community. Neither our clients nor our employees are a commodity. They are part of our family.

The followings are the top 10 reasons you should trust your online business and hosting needs to us:

- FREE domain for Life - ASPHostDirectory gives you your own free domain name for life with our Professional Hosting Plan and 3 free domains with any of Reseller Hosting Plan! There’s no need to panic about renewing your domain as ASPHostDirectory will automatically do this for you to ensure you never lose the all important identity of your site
- 99,9% Uptime Guarantee - ASPHostDirectory promises it’s customers 99.9% network uptime! We are so concerned about uptime that we set up our own company to monitor people’s uptime for them called ASPHostDirectory Uptime
- 24/7-based Support - We never fall asleep and we run a service that is opening 24/7 a year. Even everyone is on holiday during Easter or Christmast/New Year, we are always behind our desk serving our customers
- Customer Tailored Support - if you compare our hosting plans to others you will see that we are offering a much better deal in every aspect; performance, disk quotas, bandwidth allocation, databases, security, control panel features, e-mail services, real-time stats, and service
- Money Back Guarantee - ASPHostDirectory offers a ‘no questions asked’ money back guarantee with all our plans for any cancellations made within the first 30 days of ordering. Our cancellation policy is very simple - if you cancel your account within 30 days of first signing up we will provide you with a full refund
- Experts in Visual Studio 2010 Hosting - Given the scale of our environment, we have recruited and developed some of the best talent in the hosting technology that you are using. Our team is strong because of the experience and talents of the individuals who make up ASPHostDirectory
- Daily Backup Service - We realise that your website is very important to your business and hence, we never ever forget to create a daily backup. Your database and website are backup every night into a permanent remote tape drive to ensure that they are always safe and secure. The backup is always ready and available anytime you need it
- Easy Site Administration - With our powerful control panel, you can always administer most of your site features easily without even needing to contact for our Support Team. Additionally, you can also install more than 100 FREE applications directly via our Control  Panel in 1 minute!

Happy Hosting!



ASPHostDirectory ASP.NET 4.0 Hosting :: Using the FileUpload Control with ASP.NET 4.0 and C#

clock October 22, 2010 06:41 by author Darwin

This tutorial will demonstrate how to upload a file using the file upload control with ASP.NET 4.0 and C#.

Creating the Web Site

For this tutorial we will create a simple web site that will allow us to upload files to a specific folder within the web site's file structure. At this point, we have create a new ASP.NET Empty Web Site. The first thing we will need to do is setup a folder local to our web site to which we will save the uploaded files. To begin:

1. Right click the project in your solution explorer.
2. Select New Folder.
3. Name the folder 'Files'.

Next, we need to setup the web page that the user will upload files with. For this, we will be adding in a file upload control and a button. To do this:

1. Right click the project in your solution explorer.
2. Select add new item.
3. Select a web form.
4. Name it 'Default.aspx'.
5. Open Default.aspx up to design mode.
6. Drag and drop a fileupload control onto the web form.
7. Add a break line after the fileupload.
8. Drag and drop a button underneath the fileupload.
9. Change the ID property to 'btnUpload'.
10. Change the Text property to 'Upload'.

This form will allow the user to select a file and then click upload to actually upload it to the web site.


Uploading Files

Next, we need to add some C# code that will actually upload a file in the event that the upload button is clicked and a file has been selected. To do this:

1. Open up Default.aspx to design mode.
2. Double click btnUpload to generate the click event method for it.
3. Add the following using statements at the top of the Default.aspx.cs class:

using System.IO;

4. Add the following code to the btnUpload_Click event method:

protected void btnUpload_Click(object sender, EventArgs e)
{
       //check to make sure a file is selected
       if (FileUpload1.HasFile)
       {
            //create the path to save the file to
            string fileName = Path.Combine(Server.MapPath("~/Files"), FileUpload1
            //save the file to our local path
            FileUpload1.SaveAs(fileName);
       }
}


Testing

To test this out, load up the web site and:

1. Click browse.
2. Select a file.
3. Click open.
4. Click upload.
5. Close the web site.

What this has done is uploaded the file that you selected to the Files folder of our web site. To view the file that was uploaded, open up your solution explorer and click the refresh icon. The file should now be listed in your files folder.

The Default.aspx source looks like this:

<body>
    <form id="form1" runat="server">
    <div>
        <asp:FileUpload ID="FileUpload1" runat="server" />
        <br />
        <asp:Button ID="btnUpload" runat="server" Text="Upload" 
            onclick="btnUpload_Click" />
    </div>
    </form>
</body>


What is so SPECIAL on ASPHostDirectory.com ASP.NET 4.0 Hosting?

We know that finding a cheap, reliable web host is not a simple task so we’ve put all the information you need in one place to help you make your decision. At ASPHostDirectory, we pride ourselves in our commitment to our customers and want to make sure they have all the details they need before making that big decision.

We will work tirelessly to provide a refreshing and friendly level of customer service. We believe in creativity, innovation, and a competitive spirit in all that we do. We are sound, honest company who feels that business is more than just the bottom line. We consider every business opportunity a chance to engage and interact with our customers and our community. Neither our clients nor our employees are a commodity. They are part of our family.

The followings are the top 10 reasons you should trust your online business and hosting needs to us:

- FREE domain for Life - ASPHostDirectory gives you your own free domain name for life with our Professional Hosting Plan and 3 free domains with any of Reseller Hosting Plan! There’s no need to panic about renewing your domain as ASPHostDirectory will automatically do this for you to ensure you never lose the all important identity of your site
- 99,9% Uptime Guarantee - ASPHostDirectory promises it’s customers 99.9% network uptime! We are so concerned about uptime that we set up our own company to monitor people’s uptime for them called ASPHostDirectory Uptime
- 24/7-based Support - We never fall asleep and we run a service that is opening 24/7 a year. Even everyone is on holiday during Easter or Christmast/New Year, we are always behind our desk serving our customers
- Customer Tailored Support - if you compare our hosting plans to others you will see that we are offering a much better deal in every aspect; performance, disk quotas, bandwidth allocation, databases, security, control panel features, e-mail services, real-time stats, and service
- Money Back Guarantee - ASPHostDirectory offers a ‘no questions asked’ money back guarantee with all our plans for any cancellations made within the first 30 days of ordering. Our cancellation policy is very simple - if you cancel your account within 30 days of first signing up we will provide you with a full refund
- Experts in ASP.NET 4.0 Hosting - Given the scale of our environment, we have recruited and developed some of the best talent in the hosting technology that you are using. Our team is strong because of the experience and talents of the individuals who make up ASPHostDirectory
- Daily Backup Service - We realise that your website is very important to your business and hence, we never ever forget to create a daily backup. Your database and website are backup every night into a permanent remote tape drive to ensure that they are always safe and secure. The backup is always ready and available anytime you need it
- Easy Site Administration - With our powerful control panel, you can always administer most of your site features easily without even needing to contact for our Support Team. Additionally, you can also install more than 100 FREE applications directly via our Control  Panel in 1 minute!

Happy Hosting!



ASPHostDirectory ASP.NET 4.0 Hosting :: Upgrade an ASP.NET Web Application to ASP.NET 4.0

clock October 18, 2010 08:16 by author Darwin

Upgrade an Application's Web.config File from the .NET Framework 3.5 to the .NET Framework 4

1. Make sure that the application currently targets ASP.NET 3.5.

2. Open the Web.config file in the application root.

3. In the configSections section, remove the sectionGroup element that is named "system.web.extensions".

4. In the system.web section, in the compilation collection, remove every add element that refers to an assembly of the .NET Framework.

Framework assemblies generally begin with "System.". Typically these have Version=3.5.0.0 in the assembly attribute. However, some assembly entries that have the 3.5.0.0 version number might refer to assemblies that were installed as part of add-on releases, or to custom assemblies. Do not delete these. If the Web.config file contains any of these references, you must investigate them individually to determine whether a later version is available and whether the version reference must be changed.

5. Add a targetFramework attribute to the compilation element in the system.web section, as shown in the following example:

<compilation targetFramework="4.0">

In the opening tag for the pages section, add a controlRenderingCompatibility attribute, as shown in the following example:

<pages controlRenderingCompatibilityVersion="3.5"/>

Many ASP.NET 4 controls render HTML that is compliant with XHTML and accessibility standards. However, the Web site that you are converting might have CSS rules or client script that will not work correctly if Web pages change the way they render HTML. If you want to take advantage of the control rendering enhancements in ASP.NET 4, you can omit this attribute.

6.
In the system.codedom section, in the compilers collection, remove the compiler elements for c# and vb.

7.
Delete everything between the system.webserver section start and end tags, but leave the tags themselves.

8.
Delete everything between the runtime section start and end tags, but leave the tags themselves.

9.
If you have customized the Web.config file, and if any customizations refer to custom assemblies or classes, make sure that the assemblies or classes are compatible with the .NET Framework version 4.

The following example shows an example Web.config file for a simple Web application that was converted from the .NET Framework version 3.5 to the .NET Framework version 4.

<?xml version="1.0"?>
<!--
    Note: As an alternative to hand editing this file you can use the
    web admin tool to configure settings for your application. Use
    the Website->Asp.Net Configuration option in Visual Studio.
    A full list of settings and comments can be found in
    machine.config.comments usually located in
    \Windows\Microsoft.Net\Framework\v2.x\Config
-->
<configuration>
  <appSettings/>
  <connectionStrings>
    <add name="NorthwindConnection" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\NORTHWND.MDF;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
  </connectionStrings>
  <system.web>
<!--
    Set compilation debug="true" to insert debugging
    symbols into the compiled page. Because this
    affects performance, set this value to true only
    during development.
-->
  <compilation debug="true" targetFramework="4.0">
    <assemblies>
    </assemblies>
  </compilation>
<!--
    The <authentication> section enables configuration
    of the security authentication mode used by
    ASP.NET to identify an incoming user.
-->
  <authentication mode="Windows"/>
<!--
    The <customErrors> section enables configuration
    of what to do if/when an unhandled error occurs
    during the execution of a request. Specifically,
    it enables developers to configure html error pages
    to be displayed in place of a error stack trace.
        <customErrors mode="RemoteOnly"
defaultRedirect="GenericErrorPage.htm">
            <error statusCode="403" redirect="NoAccess.htm" />
            <error statusCode="404" redirect="FileNotFound.htm" />
        </customErrors>
-->
  <pages controlRenderingCompatibilityVersion="3.5"/></system.web>
  <system.codedom>
  </system.codedom>
<!--
    The system.webServer section is required for running ASP.NET AJAX under Internet
    Information Services 7.0.  It is not necessary for previous version of
IIS.
-->
  <system.webServer>
  </system.webServer>
</configuration>

Associate an IIS Application with the .NET Framework 4 in IIS 7.0

1. In Windows, start Inetmgr.

2. In the Connections pane, expand the server node and then click Application Pools.

3. On the Application Pools page, select the application pool that contains the application that you want to change.

4. In the Actions pane, click View Applications.

5. Select the application whose application pool hat you want to change and then click Change Application Pool in the Actions pane.

6. In the Select Application Pool dialog box, select an application pool that is associated with .NET Framework version 4 from the Application pool list, and then click OK
.

What is so SPECIAL on ASPHostDirectory.com ASP.NET 4.0 Hosting?

We know that finding a cheap, reliable web host is not a simple task so we’ve put all the information you need in one place to help you make your decision. At ASPHostDirectory, we pride ourselves in our commitment to our customers and want to make sure they have all the details they need before making that big decision.

We will work tirelessly to provide a refreshing and friendly level of customer service. We believe in creativity, innovation, and a competitive spirit in all that we do. We are sound, honest company who feels that business is more than just the bottom line. We consider every business opportunity a chance to engage and interact with our customers and our community. Neither our clients nor our employees are a commodity. They are part of our family.

The followings are the top 10 reasons you should trust your online business and hosting needs to us:

- FREE domain for Life - ASPHostDirectory gives you your own free domain name for life with our Professional Hosting Plan and 3 free domains with any of Reseller Hosting Plan! There’s no need to panic about renewing your domain as ASPHostDirectory will automatically do this for you to ensure you never lose the all important identity of your site
- 99,9% Uptime Guarantee - ASPHostDirectory promises it’s customers 99.9% network uptime! We are so concerned about uptime that we set up our own company to monitor people’s uptime for them called ASPHostDirectory Uptime
- 24/7-based Support - We never fall asleep and we run a service that is opening 24/7 a year. Even everyone is on holiday during Easter or Christmast/New Year, we are always behind our desk serving our customers
- Customer Tailored Support - if you compare our hosting plans to others you will see that we are offering a much better deal in every aspect; performance, disk quotas, bandwidth allocation, databases, security, control panel features, e-mail services, real-time stats, and service
- Money Back Guarantee - ASPHostDirectory offers a ‘no questions asked’ money back guarantee with all our plans for any cancellations made within the first 30 days of ordering. Our cancellation policy is very simple - if you cancel your account within 30 days of first signing up we will provide you with a full refund
- Experts in ASP.NET 4.0 Hosting - Given the scale of our environment, we have recruited and developed some of the best talent in the hosting technology that you are using. Our team is strong because of the experience and talents of the individuals who make up ASPHostDirectory
- Daily Backup Service - We realise that your website is very important to your business and hence, we never ever forget to create a daily backup. Your database and website are backup every night into a permanent remote tape drive to ensure that they are always safe and secure. The backup is always ready and available anytime you need it
- Easy Site Administration - With our powerful control panel, you can always administer most of your site features easily without even needing to contact for our Support Team. Additionally, you can also install more than 100 FREE applications directly via our Control  Panel in 1 minute!

Happy Hosting!

 



ASPHostDirectory ASP.NET 4 Hosting :: Create a Database using Model-First Development

clock July 13, 2010 05:17 by author Darwin

Creating a Database using Model-First Development

Step 1: Create a new solution


1. Launch Visual Studio 2010 Beta 2.
2. Click the New Project link on the Start Page.  The New Project dialog box should appear.
3. Click on the Visual C# node from the tree view of installed templates.
4. Select Empty ASP.NET Web Application from the list of templates.
5. Enter OrderSystem for the project name and click the OK button.

Visual Studio will create a solution file in the folder you specified and also create a sub folder that contains the web site's project file and config files.

Step 2: Create an ADO.NET Entity Data Model

The next step is to create the ADO.NET Entity Data Model.  For this application we'll model the concept of users and addresses.  A user can have more that one address so we'll build an entity data model that models this relationship.

1. Right click on the OrderSystem project in the Solution Explorer and select Add à New Item…
2. Click the Data node under the Visual C# node in the Installed Templates tree.
3. Select the ADO.NET Entity Data Model template.
4. Change the name to OrderDB.edmx and click the Add button.
5. Visual Studio will display the Entity Data Model Wizard.  This is where you can decide to build the model from an existing database or create the model first and then build the database.
6. Choose Empty model from the wizard and click the Finish button.

Step 3: Create the Entities and Associations

The next step is to model the user and user's addresses relationship. Let's first create the user entity.

1. Right click on the Entity Data Model Designer and select AddàEntity… from the pop-up menu.
2. The Add Entity dialog box should appear.  Enter UserAccount for the Entity name.  Notice that as you type the Entity name the Entity Set name pluralizes the Entity name.  Think of the Entity name as the class that represents a record and the Entity set as the class that represents the table of those records.
3. By default the Entity Framework will create a Primary Key called Id.  If you wish to not create a primary key you can uncheck the Create key property checkbox from the dialog box.
4. Click the OK button. The UserAccount entity will be added to the entity diagram.
5. The next step is to add properties to this entity. Properties will map to fields in a table. We'll first add the First and Last name properties.
6. Right click on the UserAccount entity and select AddàScalar property from the pop-up menu.
7. Change the property name to FirstName.
8. In the properties window change the MaxLength to 50. Scalar properties are strings by default.
9. Add another property called LastName the same way and set its MaxLength to 50.

The next step is to add and insert date and update date properties.  We like to have the inserted and updated dates on every entity just for the sake of trouble shooting.  These are two properties that will be added to every entity so it is the perfect candidate for a Complex Type.  A Complex Type allows you to define a set of properties and then associate them with multiple entities.

10. In the Model Browser window, left click on the Complex Types nodes. 
11. Change the name of the complex type to AuditFields.
12. Right click on the AuditFields complex type in the Model Browser and select AddàScalar PropertyàDateTime from the pop-up menu.
13. Change the name to InsertDate.
14. Follow the same steps to add the UpdateDate property to the complex type.
15. Now you can add the Complex property to the UserAccount entity.  Right click the UserAccount entity and select AddàComplex Property from the pop-up menu.
16. Change the name to AuditFields.  The type should have already defaulted to AuditFields.

When the database is created from this entity it will contain the two audit fields defined in the complex type.

Now let's add the address entity.  A user can have more than one address so there is a one-to-many relationship between these two entities.

17. Right click the designer and select AddàEntity from the pop-up menu.
18. Change the name to Address and then click the OK button.
19. Add scalar properties to the Address entity for Address1, Address2, City, State, and Zip. 
20. Change Address2 to be nullable by settting the Nullable property to True in the properties window.  All other properties are required.
21. Now add the Audit Fields to this entity by right clicking the Address entity and selecting AddàComplex Property from the pop-up menu.  Set the name to AuditFields and the type to AuditFields.

The next step is to create an association between the UserAccount and Address entities.

22. Right click on the UserAccount entity and select AddàAssociation from the pop-up menu.
23. The Add Association dialog appears.  It assumes correctly that you want to create a one-to-many relationship between these two entities.  You use the Multiplicity drop down to define the variations of relationships but for this example you can leave the defaults and click the OK button.  Notice that a UserAccountId property was added to the Address table.

Step 4: Generate the Database

Now that the entities are defined we can create the database.  Visual Studio makes this quite simple.  A script is generated with the correct DDL statements to create tables, indexes, and relationships which you can then execute against your database

1. Right click on the Designer and select Generate Database from Model… from the pop-up menu.  The Generate Database Wizard will appear.
2. Click the New Connection… button.
3. Enter your server name.  Choose either User Windows Authentication or Use SQL Server Authentication. 
4. Enter OrderSystem for the name of the database and click the OK button.
5. You should get a message stating "The database 'OrderSystem' does not exist or you do not have permissions to see it.  Would you like to attempt to create it?"  Click the Yes button.
6. The database should be created and you'll be returned to the Generate Database Wizard dialog.  Click the Next button.
7. The wizard will now generate the DDL statements needed to create this database.
8. Click the Finish button.


Summary

That's all you need to do to create a database using the new Entity Framework's Model First methodology. This is a big improvement over the first edition because it allows you to use Visual Studio to work through the design of you objects first and then VS can figure out how to create the database tables, indexes, and relationships for you.

What is so SPECIAL on ASPHostDirectory.com ASP. Net 4 Hosting?

We know that finding a cheap, reliable web host is not a simple task so we’ve put all the information you need in one place to help you make your decision. At ASPHostDirectory, we pride ourselves in our commitment to our customers and want to make sure they have all the details they need before making that big decision.

We will work tirelessly to provide a refreshing and friendly level of customer service. We believe in creativity, innovation, and a competitive spirit in all that we do. We are sound, honest company who feels that business is more than just the bottom line. We consider every business opportunity a chance to engage and interact with our customers and our community. Neither our clients nor our employees are a commodity. They are part of our family.

The followings are the top 10 reasons you should trust your online business and hosting needs to us:

- FREE domain for Life - ASPHostDirectory gives you your own free domain name for life with our Professional Hosting Plan and 3 free domains with any of Reseller Hosting Plan! There’s no need to panic about renewing your domain as ASPHostDirectory will automatically do this for you to ensure you never lose the all important identity of your site
- 99,9% Uptime Guarantee - ASPHostDirectory promises it’s customers 99.9% network uptime! We are so concerned about uptime that we set up our own company to monitor people’s uptime for them called ASPHostDirectory Uptime
- 24/7-based Support - We never fall asleep and we run a service that is opening 24/7 a year. Even everyone is on holiday during Easter or Christmast/New Year, we are always behind our desk serving our customers
- Customer Tailored Support - if you compare our hosting plans to others you will see that we are offering a much better deal in every aspect; performance, disk quotas, bandwidth allocation, databases, security, control panel features, e-mail services, real-time stats, and service
- Money Back Guarantee - ASPHostDirectory offers a ‘no questions asked’ money back guarantee with all our plans for any cancellations made within the first 30 days of ordering. Our cancellation policy is very simple - if you cancel your account within 30 days of first signing up we will provide you with a full refund
- Experts in ASP. Net 4 Hosting - Given the scale of our environment, we have recruited and developed some of the best talent in the hosting technology that you are using. Our team is strong because of the experience and talents of the individuals who make up ASPHostDirectory
- Daily Backup Service - We realise that your website is very important to your business and hence, we never ever forget to create a daily backup. Your database and website are backup every night into a permanent remote tape drive to ensure that they are always safe and secure. The backup is always ready and available anytime you need it
- Easy Site Administration - With our powerful control panel, you can always administer most of your site features easily without even needing to contact for our Support Team. Additionally, you can also install more than 100 FREE applications directly via our Control  Panel in 1 minute!

Happy Hosting!

 



ASPHostDirectory ASP.NET 4 Hosting :: What's New in C# and .NET 4

clock July 6, 2010 05:54 by author Darwin

While .NET 3.0 and 3.5 were great additions to the .NET framework, they were built against the 2.0 Common Language Runtime (CLR). Now, Microsoft has released .NET 4 – in addition to a new CLR, we've got a ton of framework and language improvements. We'll cover some of those changes here and will continue to cover .NET 4 in future article.

C# Language

Let's start by covering a few of the new features of the C# language. After that, we'll check out some IDE enhancements to make your C# development experience more productive.

Named and Optional Arguments

With support for named arguments, you can reduce the amount of typing you need to do when calling a method (or indexer, constructor or delegate).

Let's say you have a method with 4 arguments (x, y, width and height). And because this API was designed nicely, the arguments are actually named "x", "y", "width" and "height". When it comes time to calling that method, if you can only remember the argument names but not their position, named arguments will help:


CalulateIntersection(x: 20, y: 30, height: 10, width: 4);

Or maybe it was width and height that went first?

CalulateIntersection(height: 10, width: 4, x: 20, y: 30);

With named arguments, both of these calls are equivalent and pass the same data to the method.

Optional arguments allow you to specify a default value for an argument. The default value will be used if the caller does not provide a value for the optional parameter. The syntax is simple:

public void MakeBeta(int value, string name = "Beta1", string version = "1.0")

In the method signature above, name and version are optional. If not supplied by the caller, "name" will get the value "Beta1" and "version" will be "1.0". Even though optional parameters are, um, optional, you can't leave them out altogether. If you wanted to call "MakeBeta" with the default name but a specific version, you can use named arguments:

MakeBeta(34, version: "2.4");

If you've done any COM-interop, especially with the Microsoft Office COM API's, you'll quickly see how powerful optional and named arguments will be to you. Before named arguments, you had to use Type.Missing for optional parameters:

excelApp.get_Range("A5", "C7").AutoFormat(myFormat, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing);


Now you can take advantage of named arguments and simply supply the format argument:

excelApp.get_Range("A5", "C7").AutoFormat(format:myFormat);

Dynamic keyword

The "dynamic" keyword allows you to define a type that has its type checking done at runtime rather than compile time. Why would you want to wait until runtime to do your type checking? It allows your application to be more flexible: You don't care where an object came from – COM interop, reflection, a dynamic language like IronPython – you just want to manipulate it.


Consider this example:

public void DoSomething(dynamic x)
      {
            x.ShowSample();
      }

Since "x" is defined as dynamic, no compile-time checks are done. At runtime, the code will work only if the object passed in supports a "ShowSample" method that takes no arguments. It doesn't matter what the type is – as long as it has a "ShowSample" method.

Why defer type checking to runtime? The biggest reason is COM-interop. If you look at some of the Microsoft Office Automation API interfaces, there are a lot of variables and return types defined as "object". This is because the API's were originally designed for a non-type-safe language: VBScript.


With .NET's adherence to strong typing, interop with COM API's like the Microsoft Office API's requires a lot of casting to various interfaces and classes in both method calls as well as return types. It made the code tedious to write and difficult to read.


With the dynamic keyword, we can let the runtime do the type checking and casting for us. A call to set or get the value of a range used to look something like this:

      ((Microsoft.Office.Interop.Excel.Range)excelApp.Cells[5, 5]).Value = "Language";
      var languageRange = (Microsoft.Office.Interop.Excel.Range)excelApp.Cells[5, 5];


Now, by defining the "excelApp" variable as "dynamic", we can let the runtime do the type checking and there is no longer a need to satisfy the compiler with casting:

      excelApp.Cells[5, 5].Value = "Language";
      var languageRange = excelApp.Cells[5, 5];

Type Equivalence Support

Type Equivalence Support (or "Type Embedding") allows you to avoid a major pitfall of writing clients against strongly-type interop assemblies; that is, when a new version of the strongly-typed interop assembly is released, you have to recompile your client – even if you're not using any of the new features.

With type embedding, you can actually embed type information into a client. So if the type information changes on the target machine (because the user upgraded to the next version of Microsoft Office, for example), the type information embedded into the client can be used without the need to recompile the client application.

A simple example of how this works is beyond the scope of this article. See the MSDN documentation on "Walkthrough: Embedding Types from Managed Assemblies" for a complete explanation and sample code.


Covariance and Contravariance

This is one of those tricky things that could take up an entire article. As a matter of fact, former "C# Corner" author Bill Wagner did just that back in May of 2009. His article, "Generic Covariance and Contravariance in C# 4.0" provides an in-depth look at how C# handles type conversions and decides which ones are allowed and which aren't.

C# IDE

The C# language wasn't the only part of C# that was improved. Microsoft spent a lot of time on Visual Studio as well. The IDE shell was rewritten in WPF (ever heard of the term "eating your own dog food?") and uses MEF (Managed Extensibility Framework) to offer even more extensibility points. Here are a few C# IDE enhancements in 2010.

Generate From Usage

As a fan of test-first development, I like the new "Generate From Usage" feature.


Let's say we’re writing a simple banking application and we need to write some code to transfer some money between two accounts. Let’s start with a unit test:

      [TestMethod]
      public void TransferFundsTest()
      {
            Account source = new Account() {Balance = 300.0};
            Account destination = new Account() {Balance = 100.0};
            var xferService = new XferService();

            xferService.Transfer(source, destination, 50.0);

            Assert.AreEqual(250, source.Balance);
            Assert.AreEqual(150, destination.Balance);
      }

Lots of errors in there! That’s because we haven’t even written an Account class or an XferService class. Visual Studio can help us start generating some code based on our unit test.

Right-click on the one of the red "Account" instances and select "Generate" and then "Class". Visual Studio generates a simple Account class with no members. Now right-click on one of the red "Balance" references and select "Generate" and then "Property". Our Account class now has a simple get/set Balance field. Repeat these same steps with XferService and the Transfer method. Without too much work, we’ve got the following code generated from our unit tests:


      class Account
      {
            public double Balance { get; set; }
      }

      class XferService
      {
            internal void Transfer(Account source, Account destination, double p)
            {
                  throw new NotImplementedException();
            }

}

Reference Highlighting

Reference Highlighting adds a nice navigational feature to the IDE. Select any word in the IDE. You’ll notice that all instances of that word are highlighted in the code editor. It’s a quick way to show you where usages of that word object (class, variable, method, property) can be found. And you can navigate between all highlighted instances with CTRL+SHIFT+DOWN ARROW and CTRL+SHIFT+UP ARROW.

Conclusion

All in all, Microsoft has done a very nice job of putting lots of features into both C# and the Visual Studio IDE. Remember, this article covered just a few of the highlights. So, if you’re looking for ASP.NET 4.0 hosting, you can choose ASPHostDirectory as the alternatives. You can start from $ 3.99/month to get the professional ASP.NET 4.0 hosting. What are you waiting for?

What is so SPECIAL on ASPHostDirectory.com ASP. Net 4 Hosting?

We know that finding a cheap, reliable web host is not a simple task so we’ve put all the information you need in one place to help you make your decision. At ASPHostDirectory, we pride ourselves in our commitment to our customers and want to make sure they have all the details they need before making that big decision.

We will work tirelessly to provide a refreshing and friendly level of customer service. We believe in creativity, innovation, and a competitive spirit in all that we do. We are sound, honest company who feels that business is more than just the bottom line. We consider every business opportunity a chance to engage and interact with our customers and our community. Neither our clients nor our employees are a commodity. They are part of our family.

The followings are the top 10 reasons you should trust your online business and hosting needs to us:

- FREE domain for Life - ASPHostDirectory gives you your own free domain name for life with our Professional Hosting Plan and 3 free domains with any of Reseller Hosting Plan! There’s no need to panic about renewing your domain as ASPHostDirectory will automatically do this for you to ensure you never lose the all important identity of your site
- 99,9% Uptime Guarantee - ASPHostDirectory promises it’s customers 99.9% network uptime! We are so concerned about uptime that we set up our own company to monitor people’s uptime for them called ASPHostDirectory Uptime
- 24/7-based Support - We never fall asleep and we run a service that is opening 24/7 a year. Even everyone is on holiday during Easter or Christmast/New Year, we are always behind our desk serving our customers
- Customer Tailored Support - if you compare our hosting plans to others you will see that we are offering a much better deal in every aspect; performance, disk quotas, bandwidth allocation, databases, security, control panel features, e-mail services, real-time stats, and service
- Money Back Guarantee - ASPHostDirectory offers a ‘no questions asked’ money back guarantee with all our plans for any cancellations made within the first 30 days of ordering. Our cancellation policy is very simple - if you cancel your account within 30 days of first signing up we will provide you with a full refund
- Experts in ASP. Net 4 Hosting - Given the scale of our environment, we have recruited and developed some of the best talent in the hosting technology that you are using. Our team is strong because of the experience and talents of the individuals who make up ASPHostDirectory
- Daily Backup Service - We realise that your website is very important to your business and hence, we never ever forget to create a daily backup. Your database and website are backup every night into a permanent remote tape drive to ensure that they are always safe and secure. The backup is always ready and available anytime you need it
- Easy Site Administration - With our powerful control panel, you can always administer most of your site features easily without even needing to contact for our Support Team. Additionally, you can also install more than 100 FREE applications directly via our Control  Panel in 1 minute!

Happy Hosting!

 



ASPHostDirectory ASP.NET 4 Hosting :: New Syntax for HTML Encoding Output in ASP.NET 4 (and ASP.NET MVC 2)

clock July 6, 2010 05:50 by author Darwin

Today’s post covers a small, but very useful, new syntax feature being introduced with ASP.NET 4 – which is the ability to automatically HTML encode output within code nuggets.  This helps protect your applications and sites against cross-site script injection (XSS) and HTML injection attacks, and enables you to do so using a nice concise syntax.

HTML Encoding

Cross-site script injection (XSS) and HTML encoding attacks are two of the most common security issues that plague web-sites and applications.  They occur when hackers find a way to inject client-side script or HTML markup into web-pages that are then viewed by other visitors to a site.  This can be used to both vandalize a site, as well as enable hackers to run client-script code that steals cookie data and/or exploits a user’s identity on a site to do bad things.

One way to help mitigate against cross-site scripting attacks is to make sure that rendered output is HTML encoded within a page.  This helps ensures that any content that might have been input/modified by an end-user cannot be output back onto a page containing tags like <script> or <img> elements. 

How to HTML Encode Content Today

ASP.NET applications (especially those using ASP.NET MVC) often rely on using <%= %> code-nugget expressions to render output.  Developers today often use the Server.HtmlEncode() or HttpUtility.Encode() helper methods within these expressions to HTML encode the output before it is rendered.  This can be done using code like below:

<div class=”article-content”>
        <%= Server.HtmlEncode(Model.Content) %>
</div>

While this works fine, there are two downsides of it:

1. It is a little verbose
2. Developers often forget to call the Server.HtmlEncode method – and there is no easy way to verify its usage across an app

New <%: %> Code Nugget Syntax

With ASP.NET 4 we are introducing a new code expression syntax (<%:  %>) that renders output like <%= %> blocks do – but which also automatically HTML encodes it before doing so.  This eliminates the need to explicitly HTML encode content like we did in the example above.  Instead, you can just write the more concise code below to accomplish the exact same thing:

<div class=”article-content”>
       <%: Model.Content %>
</div>

We chose the <%: %> syntax so that it would be easy to quickly replace existing instances of <%= %> code blocks.  It also enables you to easily search your code-base for <%= %> elements to find and verify any cases where you are not using HTML encoding within your application to ensure that you have the correct behavior. application to ensure that you have the correct behavior.

Avoiding Double Encoding

While HTML encoding content is often a good best practice, there are times when the content you are outputting is meant to be HTML or is already encoded – in which case you don’t want to HTML encode it again. 

ASP.NET 4 introduces a new IHtmlString interface (along with a concrete implementation: HtmlString) that you can implement on types to indicate that its value is already properly encoded (or otherwise examined) for displaying as HTML, and that therefore the value should not be HTML-encoded again.  The <%: %> code-nugget syntax checks for the presence of the IHtmlString interface and will not HTML encode the output of the code expression if its value implements this interface.  This allows developers to avoid having to decide on a per-case basis whether to use <%= %> or <%: %> code-nuggets.  Instead you can always use <%: %> code nuggets, and then have any properties or data-types that are already HTML encoded implement the IHtmlString interface.

Using ASP.NET MVC HTML Helper Methods with <%: %>

For a practical example of where this HTML encoding escape mechanism is useful, consider scenarios where you use HTML helper methods with ASP.NET MVC.  These helper methods typically return HTML.  For example: the Html.TextBox() helper method returns markup like <input type=”text”/>.  With ASP.NET MVC 2 these helper methods now by default return HtmlString types – which indicates that the returned string content is safe for rendering and should not be encoded by <%: %> nuggets. 

This allows you to use these methods within both <%= %> code nugget blocks:

<%= Html.TextBoxFor(article=>article.Content) %>

As well as within <%: %> code nugget blocks:

<%: Html.TextBoxFor(article=>article.Content) %>

In both cases above the HTML content returned from the helper method will be rendered to the client as HTML – and the <%: %> code nugget will avoid double-encoding it.

This enables you to default to always using <%: %> code nuggets instead of <%= %> code blocks within your applications.  If you want to be really hardcore you can even create a build rule that searches your application looking for <%= %> usages and flags any cases it finds as an error to enforce that HTML encoding always takes place.

Scaffolding ASP.NET MVC 2 Views

When you use VS 2010 (or the free Visual Web Developer 2010 Express) to build ASP.NET MVC 2 applications, you’ll find that the views that are scaffolded using the “Add View” dialog now by default always use <%: %> blocks when outputting any content.  For example, below I’ve scaffolded a simple “Edit” view for an Article object.  Note the three usages of <%: %> code nuggets for the label, textbox, and validation message (all output with HTML helper methods):

<h2>Edit Article</h2>

<% using (Html.BeginForm()) {%>

         <fieldset>

                <div class=”editor-label”>
                       <%: Html.LabelFor(model => model.Content) %>
                </div>
                <div class=”editor-field”>
                       <%: Html.TextBoxFor(model => model.Content) %>
                       <%: Html.ValidationMessageFor(model => model.Content) %>
                </div>

Summary

The new <%: %> syntax provides a concise way to automatically HTML encode content and then render it as output.  It allows you to make your code a little less verbose, and to easily check/verify that you are always HTML encoding content throughout your site.  This can help protect your applications against cross-site script injection (XSS) and HTML injection attacks. If you looking for ASP.NET 4.0 hosting, you only need to pay $ 3.99/month to get ASP.NET 4.0 hosting. You only get this opportunity in ASPHostDirectory.

What is so SPECIAL on ASPHostDirectory.com ASP. Net 4 Hosting?

We know that finding a cheap, reliable web host is not a simple task so we’ve put all the information you need in one place to help you make your decision. At ASPHostDirectory, we pride ourselves in our commitment to our customers and want to make sure they have all the details they need before making that big decision.

We will work tirelessly to provide a refreshing and friendly level of customer service. We believe in creativity, innovation, and a competitive spirit in all that we do. We are sound, honest company who feels that business is more than just the bottom line. We consider every business opportunity a chance to engage and interact with our customers and our community. Neither our clients nor our employees are a commodity. They are part of our family.

The followings are the top 10 reasons you should trust your online business and hosting needs to us:

- FREE domain for Life - ASPHostDirectory gives you your own free domain name for life with our Professional Hosting Plan and 3 free domains with any of Reseller Hosting Plan! There’s no need to panic about renewing your domain as ASPHostDirectory will automatically do this for you to ensure you never lose the all important identity of your site
- 99,9% Uptime Guarantee - ASPHostDirectory promises it’s customers 99.9% network uptime! We are so concerned about uptime that we set up our own company to monitor people’s uptime for them called ASPHostDirectory Uptime
- 24/7-based Support - We never fall asleep and we run a service that is opening 24/7 a year. Even everyone is on holiday during Easter or Christmast/New Year, we are always behind our desk serving our customers
- Customer Tailored Support - if you compare our hosting plans to others you will see that we are offering a much better deal in every aspect; performance, disk quotas, bandwidth allocation, databases, security, control panel features, e-mail services, real-time stats, and service
- Money Back Guarantee - ASPHostDirectory offers a ‘no questions asked’ money back guarantee with all our plans for any cancellations made within the first 30 days of ordering. Our cancellation policy is very simple - if you cancel your account within 30 days of first signing up we will provide you with a full refund
- Experts in ASP. Net 4 Hosting
- Given the scale of our environment, we have recruited and developed some of the best talent in the hosting technology that you are using. Our team is strong because of the experience and talents of the individuals who make up ASPHostDirectory
- Daily Backup Service - We realise that your website is very important to your business and hence, we never ever forget to create a daily backup. Your database and website are backup every night into a permanent remote tape drive to ensure that they are always safe and secure. The backup is always ready and available anytime you need it
- Easy Site Administration - With our powerful control panel, you can always administer most of your site features easily without even needing to contact for our Support Team. Additionally, you can also install more than 100 FREE applications directly via our Control  Panel in 1 minute!

Happy Hosting!

 



ASPHostDirectory ASP.NET 4 Hosting :: How to Deploy a Database With a Web Application Project

clock June 30, 2010 06:22 by author Darwin

When you prepare to deploy a Web application project that uses one or more SQL Server databases, you can enter settings that specify database scripts that must run during deployment. These settings apply whether you deploy by using one-click publish or by using a Web deployment package.

The first two procedures in this topic provide instructions for specifying database information to deploy when the database does not already exist in the destination environment. The remaining procedures explain how to change the settings after the application has already been deployed. After you deploy an application the first time, the database will already be on the destination server. You might not want to run database scripts, or you might want to run different scripts.

Configuring for First-Time Deployment

You use the Package/Publish SQL tab of the project Properties page to configure settings that determine which scripts will run during deployment. This tab is organized in a master/detail layout. In a grid at the top, you specify databases to deploy. In the rest of the tab, you specify settings that apply to the database you have selected in the grid.

To specify databases to deploy

1. In Solution Explorer, select the project name and then select Properties.

2. In the Properties page, click the Package/Publish SQL tab.

3. In the Configuration drop-down list, select the build configuration that you want to deploy.

You can configure deployment for the Debug or Release build configurations, or for a custom build configuration that you have created by using the Configuration Manager dialog box. For example, you might want different settings for deploying to a test server and for deploying to a production server.

The default value for the Configuration list is Active. This means that the settings on this tab will apply to the build configuration that is currently selected for the project. The currently selected build configuration is shown in the main toolbar and in the Configuration Manager dialog box. (To open Configuration Manager, select it from the Build menu.)

4. Click Import from Web.config.

A row is created in the grid for each connection string that is found in the Web.config file. By default, "-Deployment" is appended to the connection string name.

5. If the Web application uses databases that are not represented by connection strings in the Web.config file, manually add a row for each of those databases. For rows that you enter manually, you can use any name that helps you remember which database the row applies to.

After you have specified the databases to deploy, you can enter settings for each database. Perform the following steps for each database that you entered in the Database Entries grid.

To enter settings for a database

1. In the Database Entries grid, select the row that you want to enter settings for.

The values that you enter in the Database Entry Details section apply only to the currently selected row in the Database Entries grid. If no rows are selected in the Database Entries grid, the Database Entry Details section is disabled.

2. In the Connection string for destination database box, enter the connection string to use during deployment.

This connection string might be different from the one that you use in the deployed Web.config file for the same database. For example, the connection string to use for deployment might need administrator permissions that you do not want the connection to have when users run the application.

3. If you want to automatically generate scripts from an existing database, select the Pull data and/or schema from an existing database check box.

By default, this check box is selected for rows in the Database Entries grid that were imported from the Web.config file. When this option is selected, the Database Scripts grid includes a row to indicate that automatically generated scripts will run in the destination database.

4. If you selected the Pull data and/or schema from an existing database check box, perform the following steps:

- In the Connection string for the source database text box, enter the connection string to use during deployment.

By default, for rows in the Database Entries grid that were imported from the Web.config file, this field is initialized to the value from the Web.config file.

- In the Database scripting options drop-down list, specify whether you want the scripts that are automatically generated for this database to duplicate only the database structures (Schema Only), to duplicate both the structures and the data (Schema and Data), or to duplicate only the data (Data Only) in the destination environment.

5. If you want to specify custom database scripts to run in the destination database during deployment, add them to the Database Scripts grid by using the Add Script button.

When you click Add Script, a Select File dialog box is displayed. This dialog box enables you to select a script that you have written and to add it to the Database Scripts grid.

6. If the rows in the Database Scripts grid are not in the order in which the scripts should run, rearrange the rows by using the up arrow and down arrow buttons.

7. In the Web.config transform file for the build configuration that you are deploying, add markup that will transform the connection string for this database to the value that it should have in the deployed Web application.

8. If you do not want the automatically generated script to run in a transaction, edit the project file to set the Transacted attribute of the script's Source element to False.

9. If the source or destination database is SQL Azure and if you are running an automatically generated script, edit the script's PreSource element in the project file so that it includes the following attributes:

targetDatabaseEngineType=SQLAzureDatabase

targetServerVersion=version100

prefetchObjects=false

Set the targetServerVersion to version100 for SQL 2008 or version105 for SQL 2008 R2.

Redeploying Without Database Changes

After you have deployed a Web application the first time, you might have to deploy it again. The following procedure describes how to disable database updates for all databases or for selected databases when you redeploy the Web application.

To redeploy without database changes

1. In Solution Explorer, right-click the project name and then click Properties.

2. Click the Package/Publish Web tab.

3. Make sure that the build configuration that you want to change settings for is selected in the Configuration drop-down list.

4. If you want to disable updating for all databases that are listed in the Database Entries grid, clear the Include all databases configured in Package/Publish SQL tab check box.

5. If you want to disable updating for selected databases that are listed in the Database Entries grid, clear the Deploy check box for each database that you do not want to run scripts for.

Redeploying By Using Automatically Generated Scripts

After you have deployed a database by using automatically generated scripts, you might make database changes and then redeploy the database. In that case, the deployment process must drop existing database objects before the objects are re-created. The following procedure describes how to specify that automatically generated scripts should include SQL Drop statements.

To redeploy a database by using automatically generated scripts

If you want the automatically generated script to drop database objects such as tables, views, and stored procedures individually before it creates new versions of these objects, edit the project file to set the ScriptDropsFirst attribute of the PreSource element of the automatically generated script to True.

This setting causes a SQL Drop statement to be generated for each database object that is created from the source database. This Drop statement for a particular object will run just before the statement that creates that object. If an object occurs in the destination database but not in the source database (typically because it was dropped from the source database after the previous deployment), no Drop statement will be generated for it.

If you want to drop the entire database before re-creating individual database objects, set the DropDestinationDatabase attribute of the Source element to True.

Deploying Database Changes by Using Custom Scripts

After you have deployed a database, you might make database changes and then want to deploy only the changes to the destination database. This lets you preserve any data that might have been entered in the destination database. The following procedure describes how to disable automatically generated scripts and add custom scripts that update the database.

To deploy changes to a database and preserve data

1. Create custom database scripts that will make the changes that you want in the destination database.

2. In Solution Explorer, right-click the project name and then select Properties.

3. Click the Package/Publish SQL tab.

4. In the Database Scripts grid, clear the Include check boxes in the rows for scripts that should not run.

If you selected the Pull data and/or schema from an existing database check box, clear the Include check box for the automatically generated script.

5. Add the custom database scripts for the selected database by using the Add Script button.

When you click Add Script, a Select File dialog box is displayed that enables you to select a script that you have written and add it to the Database Scripts grid. By default, the Include check box will be selected.

6. Optionally, if the rows in the Database Scripts grid are not in the order in which the scripts should run, rearrange the rows by using the up arrow and down arrow buttons.

What is so SPECIAL on ASPHostDirectory.com ASP. Net 4 Hosting?

We know that finding a cheap, reliable web host is not a simple task so we’ve put all the information you need in one place to help you make your decision. At ASPHostDirectory, we pride ourselves in our commitment to our customers and want to make sure they have all the details they need before making that big decision.

We will work tirelessly to provide a refreshing and friendly level of customer service. We believe in creativity, innovation, and a competitive spirit in all that we do. We are sound, honest company who feels that business is more than just the bottom line. We consider every business opportunity a chance to engage and interact with our customers and our community. Neither our clients nor our employees are a commodity. They are part of our family.

The followings are the top 10 reasons you should trust your online business and hosting needs to us:

- FREE domain for Life - ASPHostDirectory gives you your own free domain name for life with our Professional Hosting Plan and 3 free domains with any of Reseller Hosting Plan! There’s no need to panic about renewing your domain as ASPHostDirectory will automatically do this for you to ensure you never lose the all important identity of your site
- 99,9% Uptime Guarantee - ASPHostDirectory promises it’s customers 99.9% network uptime! We are so concerned about uptime that we set up our own company to monitor people’s uptime for them called ASPHostDirectory Uptime
- 24/7-based Support - We never fall asleep and we run a service that is opening 24/7 a year. Even everyone is on holiday during Easter or Christmast/New Year, we are always behind our desk serving our customers
- Customer Tailored Support - if you compare our hosting plans to others you will see that we are offering a much better deal in every aspect; performance, disk quotas, bandwidth allocation, databases, security, control panel features, e-mail services, real-time stats, and service
- Money Back Guarantee - ASPHostDirectory offers a ‘no questions asked’ money back guarantee with all our plans for any cancellations made within the first 30 days of ordering. Our cancellation policy is very simple - if you cancel your account within 30 days of first signing up we will provide you with a full refund
- Experts in ASP. Net 4 Hosting
- Given the scale of our environment, we have recruited and developed some of the best talent in the hosting technology that you are using. Our team is strong because of the experience and talents of the individuals who make up ASPHostDirectory
- Daily Backup Service - We realise that your website is very important to your business and hence, we never ever forget to create a daily backup. Your database and website are backup every night into a permanent remote tape drive to ensure that they are always safe and secure. The backup is always ready and available anytime you need it
- Easy Site Administration - With our powerful control panel, you can always administer most of your site features easily without even needing to contact for our Support Team. Additionally, you can also install more than 100 FREE applications directly via our Control  Panel in 1 minute!

Happy Hosting!

 



ASPHostDirectory ASP.NET 4 Hosting :: How to Deploy a Database With a Web Application Project

clock June 30, 2010 06:22 by author Darwin

When you prepare to deploy a Web application project that uses one or more SQL Server databases, you can enter settings that specify database scripts that must run during deployment. These settings apply whether you deploy by using one-click publish or by using a Web deployment package.

The first two procedures in this topic provide instructions for specifying database information to deploy when the database does not already exist in the destination environment. The remaining procedures explain how to change the settings after the application has already been deployed. After you deploy an application the first time, the database will already be on the destination server. You might not want to run database scripts, or you might want to run different scripts.

Configuring for First-Time Deployment

You use the Package/Publish SQL tab of the project Properties page to configure settings that determine which scripts will run during deployment. This tab is organized in a master/detail layout. In a grid at the top, you specify databases to deploy. In the rest of the tab, you specify settings that apply to the database you have selected in the grid.

To specify databases to deploy

1. In Solution Explorer, select the project name and then select Properties.

2. In the Properties page, click the Package/Publish SQL tab.

3. In the Configuration drop-down list, select the build configuration that you want to deploy.

You can configure deployment for the Debug or Release build configurations, or for a custom build configuration that you have created by using the Configuration Manager dialog box. For example, you might want different settings for deploying to a test server and for deploying to a production server.

The default value for the Configuration list is Active. This means that the settings on this tab will apply to the build configuration that is currently selected for the project. The currently selected build configuration is shown in the main toolbar and in the Configuration Manager dialog box. (To open Configuration Manager, select it from the Build menu.)

4. Click Import from Web.config.

A row is created in the grid for each connection string that is found in the Web.config file. By default, "-Deployment" is appended to the connection string name.

5. If the Web application uses databases that are not represented by connection strings in the Web.config file, manually add a row for each of those databases. For rows that you enter manually, you can use any name that helps you remember which database the row applies to.

After you have specified the databases to deploy, you can enter settings for each database. Perform the following steps for each database that you entered in the Database Entries grid.

To enter settings for a database

1. In the Database Entries grid, select the row that you want to enter settings for.

The values that you enter in the Database Entry Details section apply only to the currently selected row in the Database Entries grid. If no rows are selected in the Database Entries grid, the Database Entry Details section is disabled.

2. In the Connection string for destination database box, enter the connection string to use during deployment.

This connection string might be different from the one that you use in the deployed Web.config file for the same database. For example, the connection string to use for deployment might need administrator permissions that you do not want the connection to have when users run the application.

3. If you want to automatically generate scripts from an existing database, select the Pull data and/or schema from an existing database check box.

By default, this check box is selected for rows in the Database Entries grid that were imported from the Web.config file. When this option is selected, the Database Scripts grid includes a row to indicate that automatically generated scripts will run in the destination database.

4. If you selected the Pull data and/or schema from an existing database check box, perform the following steps:

- In the Connection string for the source database text box, enter the connection string to use during deployment.

By default, for rows in the Database Entries grid that were imported from the Web.config file, this field is initialized to the value from the Web.config file.

- In the Database scripting options drop-down list, specify whether you want the scripts that are automatically generated for this database to duplicate only the database structures (Schema Only), to duplicate both the structures and the data (Schema and Data), or to duplicate only the data (Data Only) in the destination environment.

5. If you want to specify custom database scripts to run in the destination database during deployment, add them to the Database Scripts grid by using the Add Script button.

When you click Add Script, a Select File dialog box is displayed. This dialog box enables you to select a script that you have written and to add it to the Database Scripts grid.

6. If the rows in the Database Scripts grid are not in the order in which the scripts should run, rearrange the rows by using the up arrow and down arrow buttons.

7. In the Web.config transform file for the build configuration that you are deploying, add markup that will transform the connection string for this database to the value that it should have in the deployed Web application.

8. If you do not want the automatically generated script to run in a transaction, edit the project file to set the Transacted attribute of the script's Source element to False.

9. If the source or destination database is SQL Azure and if you are running an automatically generated script, edit the script's PreSource element in the project file so that it includes the following attributes:

targetDatabaseEngineType=SQLAzureDatabase

targetServerVersion=version100

prefetchObjects=false

Set the targetServerVersion to version100 for SQL 2008 or version105 for SQL 2008 R2.

Redeploying Without Database Changes

After you have deployed a Web application the first time, you might have to deploy it again. The following procedure describes how to disable database updates for all databases or for selected databases when you redeploy the Web application.

To redeploy without database changes

1. In Solution Explorer, right-click the project name and then click Properties.

2. Click the Package/Publish Web tab.

3. Make sure that the build configuration that you want to change settings for is selected in the Configuration drop-down list.

4. If you want to disable updating for all databases that are listed in the Database Entries grid, clear the Include all databases configured in Package/Publish SQL tab check box.

5. If you want to disable updating for selected databases that are listed in the Database Entries grid, clear the Deploy check box for each database that you do not want to run scripts for.

Redeploying By Using Automatically Generated Scripts

After you have deployed a database by using automatically generated scripts, you might make database changes and then redeploy the database. In that case, the deployment process must drop existing database objects before the objects are re-created. The following procedure describes how to specify that automatically generated scripts should include SQL Drop statements.

To redeploy a database by using automatically generated scripts

If you want the automatically generated script to drop database objects such as tables, views, and stored procedures individually before it creates new versions of these objects, edit the project file to set the ScriptDropsFirst attribute of the PreSource element of the automatically generated script to True.

This setting causes a SQL Drop statement to be generated for each database object that is created from the source database. This Drop statement for a particular object will run just before the statement that creates that object. If an object occurs in the destination database but not in the source database (typically because it was dropped from the source database after the previous deployment), no Drop statement will be generated for it.

If you want to drop the entire database before re-creating individual database objects, set the DropDestinationDatabase attribute of the Source element to True.

Deploying Database Changes by Using Custom Scripts

After you have deployed a database, you might make database changes and then want to deploy only the changes to the destination database. This lets you preserve any data that might have been entered in the destination database. The following procedure describes how to disable automatically generated scripts and add custom scripts that update the database.

To deploy changes to a database and preserve data

1. Create custom database scripts that will make the changes that you want in the destination database.

2. In Solution Explorer, right-click the project name and then select Properties.

3. Click the Package/Publish SQL tab.

4. In the Database Scripts grid, clear the Include check boxes in the rows for scripts that should not run.

If you selected the Pull data and/or schema from an existing database check box, clear the Include check box for the automatically generated script.

5. Add the custom database scripts for the selected database by using the Add Script button.

When you click Add Script, a Select File dialog box is displayed that enables you to select a script that you have written and add it to the Database Scripts grid. By default, the Include check box will be selected.

6. Optionally, if the rows in the Database Scripts grid are not in the order in which the scripts should run, rearrange the rows by using the up arrow and down arrow buttons.

What is so SPECIAL on ASPHostDirectory.com ASP. Net 4 Hosting?

We know that finding a cheap, reliable web host is not a simple task so we’ve put all the information you need in one place to help you make your decision. At ASPHostDirectory, we pride ourselves in our commitment to our customers and want to make sure they have all the details they need before making that big decision.

We will work tirelessly to provide a refreshing and friendly level of customer service. We believe in creativity, innovation, and a competitive spirit in all that we do. We are sound, honest company who feels that business is more than just the bottom line. We consider every business opportunity a chance to engage and interact with our customers and our community. Neither our clients nor our employees are a commodity. They are part of our family.

The followings are the top 10 reasons you should trust your online business and hosting needs to us:

- FREE domain for Life - ASPHostDirectory gives you your own free domain name for life with our Professional Hosting Plan and 3 free domains with any of Reseller Hosting Plan! There’s no need to panic about renewing your domain as ASPHostDirectory will automatically do this for you to ensure you never lose the all important identity of your site
- 99,9% Uptime Guarantee - ASPHostDirectory promises it’s customers 99.9% network uptime! We are so concerned about uptime that we set up our own company to monitor people’s uptime for them called ASPHostDirectory Uptime
- 24/7-based Support - We never fall asleep and we run a service that is opening 24/7 a year. Even everyone is on holiday during Easter or Christmast/New Year, we are always behind our desk serving our customers
- Customer Tailored Support - if you compare our hosting plans to others you will see that we are offering a much better deal in every aspect; performance, disk quotas, bandwidth allocation, databases, security, control panel features, e-mail services, real-time stats, and service
- Money Back Guarantee - ASPHostDirectory offers a ‘no questions asked’ money back guarantee with all our plans for any cancellations made within the first 30 days of ordering. Our cancellation policy is very simple - if you cancel your account within 30 days of first signing up we will provide you with a full refund
- Experts in ASP. Net 4 Hosting
- Given the scale of our environment, we have recruited and developed some of the best talent in the hosting technology that you are using. Our team is strong because of the experience and talents of the individuals who make up ASPHostDirectory
- Daily Backup Service - We realise that your website is very important to your business and hence, we never ever forget to create a daily backup. Your database and website are backup every night into a permanent remote tape drive to ensure that they are always safe and secure. The backup is always ready and available anytime you need it
- Easy Site Administration - With our powerful control panel, you can always administer most of your site features easily without even needing to contact for our Support Team. Additionally, you can also install more than 100 FREE applications directly via our Control  Panel in 1 minute!

Happy Hosting!

 



ASPHostDirectory ASP.NET 4 Hosting :: New Features in ASP.NET 4.0

clock June 12, 2010 06:26 by author Darwin

This topic contains information about new features in ASP.NET 4.0. This topic doesn’t provide comprehensive information about all new features and is subject to change. So, if you seek more information about ASP.NET 4.0, you can choose ASPHostDirectory as alternatives. You’ll get the best service at an affordable price. Only with @ 3.99/month, you can directly get the services you want. So, what are you waiting for? Try it!!

Adding MetaKeyword and MetaDescription Using Page object

Meta keywords and description are most important components of a page when we want to make it search engine friendly. Every search engine will look for these tags to know more information of the page contents. ASP.Net 2.0 introduced a new feature where one can add these tags from the code behind using HtmlMeta class. It would have been better if we are able to do this through Page directive (Page class).  ASP.Net 4.0 added 2 new properties on the Page object to let you define the Meta keywords and Description.

Refer the code below,

protected void Page_Load(object sender, EventArgs e)

    {

        Page.MetaKeywords = "asp.net,C#";

        Page.MetaDescription = "This is an asp.net site that hosts asp.net tutorials.";

    }

OR

<%@ Page Language="C#" AutoEventWireup="true" MetaKeywords="asp.net,C#" MetaDescription="This is an asp.net site that hosts asp.net tutorials" CodeFile="Default.aspx.cs" Inherits="_Default" %>

More Control on Controls ViewState

ViewState is one of the important factors if we start looking at improving the performance our asp.net site.  Till ASP.Net 3.x, we have EnableViewState property both at Page level and server control level to control the view state. Disabling the ViewState at page level will disable the viewstate to all the page controls. In order to improve the performance, one need to switch off the viewstate for individual control for which saving the viewstate is not necessary and hence disabling viewstate at page level is not a suitable option.  To overcome this difficulty, asp.net 4.0 added a new property to Page object and controls called ViewStateMode.

This property can take 3 values,

1. Enabled
This value will enable the view state. This is the default value for the Page object.

2. Disabled
This value will disable the viewstate

3. Inherit
This value will make the control to inherit the setting of the parent. This is the default value for a control.

With this property, we can disable the viewstate for the page and enable it for the control if only required.

Consider the following code,

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ViewStateTest.aspx.cs" ViewStateMode="Disabled" Inherits="ViewStateTest" %>

    <form id="form1" runat="server">

    <div>

        <asp:Label ID="Label1" runat="server" ViewStateMode="Enabled" Text="Default Text"></asp:Label>

        <br />

         <asp:Label ID="Label2" runat="server" Text="Default Text"></asp:Label><asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />

     </div>

    </form>

CodeBehind

protected void Page_Load(object sender, EventArgs e)

    {

        if (!IsPostBack)

        {

            Label1.Text = "Text Assigned in CodeBehind";

            Label2.Text = "Text Assigned in CodeBehind";          

        }

    }

When the page executed we will get the following output,

Text Assigned in CodeBehind

Text Assigned in CodeBehind

When the button is clicked,

Text Assigned in CodeBehind

Default Text

Since, the viewstate is disabled at page level (Page object) and the viewstate is enabled for “Label1” we will get the above output on Button click. Please note that if we have not set the value, the default will be “inherit” (for Label2).

Note

If we disabled the viewstate through EnableViewState property, setting any values for ViewStateMode property will make no impact.

ClientID Generation for ASP.Net Controls

In order to access a server control from a client side script, a developer will require getting its client id. Predicting the ClientID of any control that is packed inside a parent like UserControls, MasterPage or any DataBound controls is a challenging task till day. For example, if we have 2 TextBox control inside a page that have an associated MasterPage then the ClientID will be similar to,

<input name="ctl00$ContentPlaceHolder1$TextBox2" type="text" id="ctl00_ContentPlaceHolder1_TextBox2" />

<input name="ctl00$ContentPlaceHolder1$TextBox3" type="text" id="ctl00_ContentPlaceHolder1_TextBox3" />

This is done to make the ID of the control unique in the page.

In earlier versions for asp.net, we can register a server side hidden control which can hold the ClientID of the server control to access it from client side.

ASP.Net 4.0 addresses this difficulty by providing a new property called ClientIDMode for every controls and Page object. We can also set the property in configuration files.

This property will take the following 4 values,

1. Static
Setting this value will make the ClientID same as the ID. It will not concatenate ID of the parent naming containers.

2. Predictable
This will be useful to predict the ClientID of child controls in data controls. Setting this property will prevent the “ctlxxx” prefix in the ClientID. We will see more about this value later in this section.

3. Legacy
This value will make the ClientID generation same as earlier versions of ASP.Net

4. Inherit
This value will make the control to inherit the parent control’s setting. This is the default value for this property.

For example,

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" ClientIDMode="Static"  AutoEventWireup="true" CodeFile="ClientIDs.aspx.cs" Inherits="Default2" %>

This setting will make all the page controls to have ClientID same as ID. For example, if we have 2 Textbox control, the output will be similar to,

<input name="ctl00$ContentPlaceHolder1$TextBox2" type="text" id="TextBox2" />

<input name="ctl00$ContentPlaceHolder1$TextBox3" type="text" id="TextBox3" />

To set this property in Web.Config file/Machine.config file,

<pages clientIDMode="Static"></pages>

The above setting should be inside <System.Web> section.

Child Control’s ClientID in Data Control

For example, if we have child controls inside a ListView control the ClientID will be generated like below by default.

<div id="ListView1_itemPlaceholderContainer" style="font-family: Verdana, Arial, Helvetica, sans-serif;">               

            <span style="background-color: #DCDCDC;color: #000000;">EmpNo:

            <span id="ListView1_ctrl0_EmpNoLabel">1</span>

            <br />

            EmpName:

            <span id="ListView1_ctrl0_EmpNameLabel">Satheesh</span>

            <br />

            Address:

            <span id="ListView1_ctrl0_AddressLabel">2n Cross</span>

            <br />

            City:

            <span id="ListView1_ctrl0_CityLabel">Bangalore</span>

            <br />

            Country:

            <span id="ListView1_ctrl0_CountryLabel">India</span>

            <br />

Because the ListView control has Label control to display data in each column of every row we have SPAN tag with ClientID’s generated.

To make this ID’s predictable from clientside; we can set the ClientIDMode of the ListView control to "Predictable" and ClientIDRowSuffix to one or more number of the columns from the database.  Multiple column names should be a comma separated value. Please note that Repeater control will not support ClientIDRowSuffix property.

Consider the below,

<asp:ListView ID="ListView1" runat="server"

        DataSourceID="SqlDataSource1" ClientIDMode="Predictable" ClientIDRowSuffix="EmpName">

The above setting will remove the prefix “ctlxx” and will append the value of the column specified in ClientIDRowSuffix. This will generate the ClientID’s like,

<div id="ListView1_itemPlaceholderContainer" style="font-family: Verdana, Arial, Helvetica, sans-serif;">

            <span style="background-color: #FFF8DC;">EmpNo:

            <span id="ListView1_EmpNoLabel_Arun">2</span>

            <br />

            EmpName:

            <span id="ListView1_EmpNameLabel_Arun">Arun</span>

            <br />

            Address:

            <span id="ListView1_AddressLabel_Arun">3rd Cross</span>

            <br />

            City:

            <span id="ListView1_CityLabel_Arun">Bangalore</span>

            <br />

            Country:

            <span id="ListView1_CountryLabel_Arun">US</span>

What is so SPECIAL on ASPHostDirectory.com ASP. Net 4 Hosting?

We know that finding a cheap, reliable web host is not a simple task so we’ve put all the information you need in one place to help you make your decision. At ASPHostDirectory, we pride ourselves in our commitment to our customers and want to make sure they have all the details they need before making that big decision.

We will work tirelessly to provide a refreshing and friendly level of customer service. We believe in creativity, innovation, and a competitive spirit in all that we do. We are sound, honest company who feels that business is more than just the bottom line. We consider every business opportunity a chance to engage and interact with our customers and our community. Neither our clients nor our employees are a commodity. They are part of our family.

The followings are the top 10 reasons you should trust your online business and hosting needs to us:

- FREE domain for Life - ASPHostDirectory gives you your own free domain name for life with our Professional Hosting Plan and 3 free domains with any of Reseller Hosting Plan! There’s no need to panic about renewing your domain as ASPHostDirectory will automatically do this for you to ensure you never lose the all important identity of your site
- 99,9% Uptime Guarantee - ASPHostDirectory promises it’s customers 99.9% network uptime! We are so concerned about uptime that we set up our own company to monitor people’s uptime for them called ASPHostDirectory Uptime
- 24/7-based Support - We never fall asleep and we run a service that is opening 24/7 a year. Even everyone is on holiday during Easter or Christmast/New Year, we are always behind our desk serving our customers
- Customer Tailored Support - if you compare our hosting plans to others you will see that we are offering a much better deal in every aspect; performance, disk quotas, bandwidth allocation, databases, security, control panel features, e-mail services, real-time stats, and service
- Money Back Guarantee - ASPHostDirectory offers a ‘no questions asked’ money back guarantee with all our plans for any cancellations made within the first 30 days of ordering. Our cancellation policy is very simple - if you cancel your account within 30 days of first signing up we will provide you with a full refund
- Experts in ASP. Net 4 Hosting
- Given the scale of our environment, we have recruited and developed some of the best talent in the hosting technology that you are using. Our team is strong because of the experience and talents of the individuals who make up ASPHostDirectory
- Daily Backup Service - We realise that your website is very important to your business and hence, we never ever forget to create a daily backup. Your database and website are backup every night into a permanent remote tape drive to ensure that they are always safe and secure. The backup is always ready and available anytime you need it
- Easy Site Administration - With our powerful control panel, you can always administer most of your site features easily without even needing to contact for our Support Team. Additionally, you can also install more than 100 FREE applications directly via our Control  Panel in 1 minute!

Happy Hosting!