Archive

Archive for the ‘ASP.NET’ Category

Data Type Conversions

March 28, 2010 Leave a comment

Sometimes we have to change the data that we are using. Sometimes this change may change the value of the data or sometimes it just changes the memory space allocated by that data. This change is called data type conversion.

Data type is converted in 2 ways. They are:

  1. Implicit conversion
  2. Explicit conversion

They are described below.

Implicit conversion:

An implicit conversion converts data automatically without losing any data. Normally, data types can implicitly converted into the data types those contain more memory space.

Example:

short firstNumber = 65;

long secondNumber = firstNumber;

Explicit conversion:

An explicit conversion convert data that are automatically can’t be converted. It may converts data from bigger size to smaller size or converts data from one type into totally different type.

Example:

short firstNumber = 65;

long secondNumber = firstNumber; //Implicit conversion

short thirdNumber = (short)secondNumber; //Explicit  conversion

Console.WriteLine(thirdNumber); //outputs 65

char a = (char)firstNumber; //Explicit conversion

Console.WriteLine(a); //outputs A

We can use some built in functions those are provided with C#.

a. Convert class:

A convert class contains numerous method those can change one data type into another type. It is another implementation of explicit conversion.

Example:

int number = 65;

char character = Convert.ToChar(number); //Conversion using System’s Class

Console.WriteLine(character);   //Output: A

b. ToString() method:

A ToString() method converts any kind of data type into String type. It doesn’t change the internal value of that data.

Example:

char character = Convert.ToChar(65); //Conversion using System’s Class

string numberString = (65).ToString();

Console.WriteLine(character); //Output: A

Console.WriteLine(numberString); //Output(value is in String form): 65

Categories: ASP.NET, OOP Concept

Verbatim Characters

March 28, 2010 Leave a comment

A verbatim string is a string that is interpreted by the compiler exactly as it is written, which means that even if the string spans multiple lines or includes escape characters, these are not interpreted by the compiler and they are included with the output. The only exception is the quotation mark character, which must be escaped so that the compiler can recognize where the string ends.

string address = @”C:\Software\Books\Beginning”;

As you can see, verbatim is indicated with an ‘@’ sign at the beginning of a string.

If you want to use a quotation mark inside a verbatim string, you must escape it by using another set of quotation marks.

Example:

string greetings = @”"”Hello everyone”".said the trainer.”;

Categories: ASP.NET, OOP Concept Tags: ,

Naming Convention

March 26, 2010 Leave a comment

.NET Naming Convention

Casing Example Remarks
Button camelCase saveButton
Form PascalCase EmployeeInformationEntryUI “UI” or “Form” word should be appened at last part
TextBox camelCase firstNameTextBox “TextBox” should be appended at last part
ComboBox camelCase employeeListComboBox
ListView camelCase emploueeListListView
Class PascalCase Calculator, Employee should be noun
Object camelCase myCalculator,employeeObj
Method PascalCase GetFullName(), Add(), Encrypt() should be verb
Variable camelCase firstName, basicSalary
Property PascalCase FirstName, BasicSalary
Interface PascalCase IPrintable, ICloneable should be started with ‘”I”
Enum PascalCase EmployeeType
Categories: ASP.NET

ASP.NET Web Site Types

March 25, 2010 Leave a comment

As a Beginner i was little bite confused when created a Project. Asked many one but no one give me a clear answer about what does it mean by those Local Host,FTP and Remote Site. So here i am now and going to tell the beginners that they are types of  ASP.NET websites. Now i am going give you a brief discussion on them:

Local IIS sites:

Local IIS sites run on your computer, handled by Internet Information Services. They are a good way to test a web site in an IIS environment, or for example, in the case of intranet sites.

In order to use local IIS sites, you must meet the following prerequisites:

  • IIS 5.0 or later installed.
  • .NET framework 2.0 or later.
  • ASP.NET enabled on local IIS.
  • Administrative privileges on local computer.

Creating local IIS sites:

Visual Studio handles the task for you, when you create a local IIS site.

Running local IIS websites:

By default, simply enter: http://localhost/YourSiteName/APage.aspx

File-System based sites:

With this project type, a website is stored on the file system. It is handy, when IIS is not installed, or when multiple developers must access the same files, in classroom settings, etc.

For testing file system sites, a Web server (included in Visual Studio) must be used.

FTP sites:

In this case, the sites are stored on a remote FTP server, and you can communicate with it using Visual Studio. You open the project, and then modify it, and VS takes care of synchronization, etc.

Active and Passive FTP mode:

  • Active FTP is for server admins, the client initializes a port for the command, and passes the address of it for the server, which attempts to initialize a port on the client for the data. This will likely fail, if the client has a firewall configured.
  • Passive FTP is for the clients. Both ports will be initialized by the client, thus avoiding the interruption by the firewall.

FTP credentials:

In most cases, when you attempt to connect to an FTP site, you must specify valid credentials. Be aware, that these credentials are passed to the server in clear text format, thus be likely the target of interception.

FTP files are cached by VS when editing them. This can cause versioning conflicts when two or more developers edit the same FTP site.

Remote sites:

Alternatively to an FTP server, you can also use a remote IIS server to publish your application on it. Although it’s a requirement for the server that FrontPage Server Extensions must be installed on it. Also, the same prerequisites exist as at the local IIS site, namely: IIS 5.0 or later, .NET 2.0 or later must be installed, and ASP.NET pages must be enabled on the server.

The creation of this type is simply as any other, Visual Studio transparently does the heavy setup work, and you can concentrate on the development.

All of them have some pros & cons:

  • Local IIS site:
    • Benefits: testability in IIS environment, site is accessible from other computers
    • Disadvantages:  demands administrative rights, can be debugged only by one user
  • File-system based site:
    • Benefits: security, no IIS needed, no administrative rights needed, multiple users can debug it at the same time
    • Disadvantages: cannot be tested in IIS environment
  • FTP site:
    • Pros: site can be tested on the server where it will be used
    • Cons: site exists only in the server; this project type cannot be created, only opened.
  • Remote site:
    • Pros: testability, access for multiple developers
    • Cons: debugging issues.
Categories: ASP.NET

Configure Projects

March 25, 2010 Leave a comment

There are four project types for creating a web application in Visual Studio, which you should be familiar with for this exam. Namely: ASP.NET Web Site, Empty Web Site, ASP.NET Web Service, and ASP.NET Web Application. I will cover ASP.NET Web Site, and ASP.NET Web Application.

ASP.NET Web Site:

This project type is file-based, and there is no project file included. So every file- whatever its extension would be- in a given folder is the part of your project. This is the default web site project type in Visual Studio (simply click on the New Web Site button on the menu (represented as an Earth globe).

This template generates a web.config file with some initial entries, and a Default.aspx page with the given code-behind file for you. Also an App_Data folder will be included to help you begin your work. The above mentioned Empty Web Site project is exactly the same as this project type, the difference is that you won’t get any content generated at startup.

ASP.NET Web Application:

You can understand the Web Site project type deeper in contrast with an ASP.NET Web Application project. If you’ve ever programmed a Windows Forms Application, you’ll find this project type very familiar. You can set references on assemblies, control the assembly information of your project with the AssemblyInfo.cs file. This type also generates .designer files for your web forms.

This project type includes a project file for your application, and only the files referenced in it will be the part of your web application, whatever else may reside in your project directory.

The compilation of a Web Application project is called classic compilation. All the files, which represent your UI (.aspx and etc) are published without compilation, thus compiled dynamically when the first user requests the page. The code files will be compiled to a single assembly, so you won’t be able to change them later.

Adding References

There are two different scenarios of adding references to assemblies, depending on which project type you use. In the case of a Web Application, simply right click the references folder, and select add reference. Because Visual Studio is responsible for compiling this type, it simply includes your reference in the project file.

When you use a Web Site project type, adding a reference is also very easy, just click on the project name in solution explorer, and select add reference. Because this type of project is compiled by ASP.NET (and not Visual Studio), the web.config file will be modified to include your reference, in the following way:

<compilation>
<assemblies>
<add assembly=”MyAssembly” …./>
</assemblies>
</compilation>

Of course, you can do this manually.

Be aware of that when you add a reference to an assembly, which isn’t included in the Global Asembly Cache, Visual Studio will generate a Bin folder in your project, and place the referenced assembly there, regardless of the project type you use. If you’ve added custom assemblies to your GAC, and reference them in your project, then you should include that assembly into your applications Bin folder, and set a reference to that copy. In this manner, you can use the XCOPY or the Copy Web Site tool to deploy your application.

Categories: ASP.NET

ASP.NET Tracing

March 25, 2010 Leave a comment

With tracing, you can access data from a running application, with the help of a browser. In ASP.NET, you can access to the following information:

  • The details of the request
  • Trace information: performance information of the Web page’s life cycle events
  • Control tree: size information about controls.
  • Session state: displays session variables and values
  • Application state: displays application variables and their values
  • Request cookie collection: list of cookies passed to the server as part of the request
  • Response cookie collections: list of cookies passed to the browser as part of the response
  • Headers collection: the list of HTTP headers sent with the request
  • Form collection: postback values.
  • QueryString collection: the variables of the query string.
  • Server variables: all server variables.

To enable tracing, you have two options: enable tracing for single pages, or for the whole application. To enable page tracing, you should set the Trace property to true in the @Page directive. Also, you can set it in code-behind, with the Page.Trace.IsEnabled = true; syntax. At page level, you can also include a TraceMode property, which sets the sort order of trace information, by time, or by category. When you set tracing at the page level, the trace output will be added to your page, so never implement this behavior in production applications.

To enable tracing for the whole application, you should modify the web.config as follows:

<system.web>
<trace ebabled=”true” requestLimit=”100” pageOutput=”false” ceMode=”sortByCategory”  localOnly=”true” mostRecent=”false” />
</system.web>

Attributes of Trace
Enabled Enable or disable tracing on the application level. This behavior can be overridden by independent pages, using the @Page directive. To enable tracing on specific pages, when application-level tracing is disabled, set the pageOutput attribute accordingly.
traceMode The possible values are SortByTime, which sorts the tracing information by time, or SortByCategory.
localOnly Decides whether tracing information should be provided just for local clients, or everyone else. Always set to true when publishing your application.
pageOutput Determines whether the tracing information should be included for pages or not. When set to false, you can view trace data in the Trace.axd site on the root level.
requestLimit Specifies the number of HTTP requests to be traced. Maximum us 10.000. Works only when application level tracing is enabled.
mostRecent Determines whether the most recent number of HTTP request should be stored in the trace information, or only the first requsetLimit number of requests.
writeToDiagnosticsTrace If set to true, tracing information will be forwarded to any trace listeners signed up to your application.

When enabled, application-level trace information can be viewed by requesting Trace.axd in the root of the application.

You can add your own tracing messages to the output, simply calling Trace.Write(string Category, string Message) or Trace.Warn(string Category, string Message). The only difference between the two is that Trace.Warn shows your message written with red letters.

Categories: ASP.NET Tags: ,

ASP.NET Web Pages

March 25, 2010 Leave a comment

ASP.NET Web pages provide the user interface for your Web applications. Now I’m goin to write how ASP.NET Pages work , to create and program. Read more…

Categories: ASP.NET

IIS Server

March 24, 2010 Leave a comment

Sometimes you have to work on different server at a time. For say, now i am working on IIS server and Xxamp server.  So either one of them will work. So my article is for those who face this kind of problem.

Running/stoping Xaamp is very easy. So i will not focus on that. I will go for IIS.

Starting / Stoping IIS

step 1     Go to Run and type cmd

step 2    In the command window type iisreset /stop and press Enter Thats it

Just like the following figure

you can start IIS in the same manner. just type  iisreset / start

Categories: ASP.NET Tags:

ASP.NET State Management

March 24, 2010 Leave a comment

1 Client-Based State Management Options

The following sections describe options for state management that involve storing information either in the page or on the client computer. For these options, no information is maintained on the server between round trips.

Read more…

Categories: ASP.NET

ASP.NET Page Life Cycle Overview

March 24, 2010 Leave a comment

When an ASP.NET page runs, the page goes through a life cycle in which it performs a series of processing steps. These include initialization, instantiating controls, restoring and maintaining state, running event handler code, and rendering. It is important for you to understand the page life cycle so that you can write code at the appropriate life-cycle stage for the effect you intend. Additionally, if you develop custom controls, you must be familiar with the page life cycle in order to correctly initialize controls, populate control properties with view-state data, and run any control behavior code. (The life cycle of a control is based on the page life cycle, but the page raises more events for a control than are available for an ASP.NET page alone.)

Read more…

Categories: ASP.NET
Follow

Get every new post delivered to your Inbox.