Archive | ASP.NET FAQ

WebGardening and Webforming

Web Gardening Image

WebGardening

Usually all the application developed by a company will be assigned to a single worker process in the IIS.This is not called as the WebGardening.Second example is not in the WebGarden environment.

But IIS adminsitrator having a chance of assigning all the availble application to more than one worker process. This is called the WebGardening.First Figure shows you WebGarden environment.

Posted in ASP.NET FAQ9 Comments

Adding Custom config section to web.config

public class TechPalleCustomConfig : ConfigurationSection
{
[ConfigurationProperty("BestTraining", DefaultValue="Palle Technologies.", IsRequired=false)]
public string BestTraining
{
get
{
return this["BestTraining"] as string;
}
}

[ConfigurationProperty("Address", IsRequired=true)]
public string Address
{
get
{
return (string) this["Address"];
}
}
}

Note : If you want to see this config section in your web.config file you have to create an object for the class “TechPalleCustomConfig”. After creating the object you will see custom config section in the web.config.

Note: This is not the tested code, Check your self for the correctness of the code.

Posted in ASP.NET FAQ1 Comment

Web.Config

Why Config file :

1.This is useful for setting any kind of application level setting

2.To give permissions to the different level of employees in the Company

3.To install/Refer and use new versions of assemblies from your project

4.For storing the Connections strings

5.To store session information, what type of sessions to be used and the State server/SQL server connection strings for storing the session data.

6.To enable or disable debugging process

Inheritence in Config Files:

1.All setting of the web.config file inherited from Machine.config file.

2.You can have more than 1 web.config file in your application/solution.

3.You will see real use of web.config file when Palle Technologies teach the Rolebased Authorization.

Posted in ASP.NET FAQ1 Comment

Script Exploit

Script exploit is something when you send any request from your browser , all the html content will be sent as a string. While sending the string to iis , some intelligent hackers can be able to change the content of the string while your string is travelling over the network. This kind of attacks intended for changing your content string is called ScriptExploit.

Posted in ASP.NET FAQ3 Comments

View State

View State:

Usually when a web page is requested by the browser , IIS will create an object for the webpage and after executing the code in the .cs file the output will be given back to the browser. Then IIS removes object from the memory. This is called stateless nature of the Server. But if you want to store any data during round-trips , ASP.net offers ViewState just for storing data in the client browser as an Hidden fields.

1.ViewState can be used for storing data across round trips.

2.View state will be stored in the client browser as an HTML Hiden fields in the form of Encoded data.

3.You should never store large data in ViewState . This is because with every request View state data has to be traveled back and forth from Client Browser and Server.

4.You can only store Serializable data in the ViewState.

5.ViewStateMAC property offers security to ViewState. i.e No one cannot be able to tamper easily the view state data.

6.ViewState internally uses StateBag object for implementing the storage mechanism.

7.Ex: Protected void Page_Load(Object sender,eventArgs e)

{

ViewState[“Name”]=”Palle Technologies”;

}

Protected void btn_Click(Object Sender, Event Args e)

{

Response.Write(“Name=”+ViewState[“Name”]);

}

Note: You can disable the ViewState at the Page level by setting EnableViewState=”false”. You can also disable the ViewState for individual controls by setting Property EnableViewState=”false”.

Posted in ASP.NET FAQ1 Comment

ASP.net page Life cycle

Below Page life cycle  events executed in the sequence.

1.Page_Init 2.LoadViewState ( If the request  is a post back ) 3. Page_Load 4.Post Back events (  Ex :Button_Click ) 5.Page_PreRender 6.SaveViewState  7.Render 8.UnLoad

What happens when these events fired.

Page_Init : 1.In the intialization Phase all the controls  UniqueID property in that page will be set. 2.All Master pages and Themes and skins will be set. 3. Post back data is not available in this phase ( If the request is post back request ) 4. Page Controls Init event is Executed before Page_InIt

LoadViewState : 1. This event is fired only when the request is PostBack request. 2. All the control properties loaded with Controls ViewState values.

Page_Load: 1.All the control loaded fully with their properties. 2.Page_Load occurs first and then the Child controls Load will happen next. Ex: If you have Text Box named ” txtAge” on the Page Patient.aspx, first Page_Load will occur and txtAge_Load happens Next.

PostBack Events: 1. Post back events like Button_Click and TextBox1_TextChanged, Dropdown list “SelectedIndex_Changed” events will be fired in this stage.

Page_PreRender: 1.Sequence is Page_PreRender followed by ChildControls_PreRender 2.Inthis event Programmer can be able to change Response object.

SaveViewState: 1.ViewState for all the controls will be saved

Page_Render: 1. This method is responsible for generating html code for the page and also for all the controls. This can be done by Calling Render method for individual controls and for the page it-self.( We will see an example for this while working with Custom Controls )

Page_UnLoad: 1. Memory created for the Page class will be removed from the server ( IIS).

Note : For more info You can visit http://msdn.microsoft.com/en-us/library/ms178472(v=VS.90).aspx

Posted in ASP.NET FAQ9 Comments