Skip to main content

Privado.com - A Private Search Engine

https://www.privado.com/ Your searches should be private. We make sure they really are.  Private Search in Action  We don’t track you  We don’t store your searches in any identifiable way  We don’t store your IP address in our services Your privacy is important.  There are no traces of your activities and personal identity in our servers.  You can learn more about privacy in our blog  We don't like cookies!   https://www.privado.com/

ASP.NET 2.0 Interview Questions with answers

 

What is IIS Metabase? How to edit IIS metabase? How to backup IIS metabase file?

 

IIS metabase is the repository of the configuration values that are set in the Internet Information Server (IIS). The IIS metabase in an XML file. It may be controlled through program or manually too.

 

In order to edit IIS metabase entries, the user needs to have administrative rights on the system. To do this, in run window, type "inetmgr". Browse to "Local Computer" and right click it. Click on "Properties". Select the "Enable Direct Metabase Edit" check box.

 

Many times, due to the existence of multiple versions of .NET framework, some settings in the IIS metabase may get affected and cause your program not to run. For such scenarios, you may take a backup of the IIS metabase XML file and recover it. To create a portable backup, open run window and type "inetmgr". Next browse to "Local Computer" and go to "All Tasks". Next, click on Backup/Restore Configuration. Next, click on "Create Backup". In the textbox box for Configuration Backup name, type a name for your backup file. Also select the encrypt backup option and type a password. To finish the process, click "OK".

 

How to start Outlook,NotePad file in AsP.NET with code ?

 

Here is the syntax to open outlook or notepad file in ASP.NET VB.NET Process.Start("Notepad.exe") Process.Start("msimn.exe"); C#.NET System.Diagnostics.Process.Start("msimn.exe"); System.Diagnostics.Process.Start("Notepad.exe");

 

What is cross page posting in ASP.NET2.0 ?

 

When we have to post data from one page to another in application we used server.transfer method but in this the URL remains the same but in cross page posting there is little different there is normal post back is done but in target page we can access values of server control in the source page.This is quite simple we have to only set the PostBackUrl property of Button,LinkButton or imagebutton which specifies the target page.In target page we can access the PreviousPage property.And we have to use the @PreviousPageType directive.We can access control of PreviousPage by using the findcontrol method.When we set the PostBackURL property ASP.NET framework bind the HTML and Javascript function automatically.

 

Describe the Provider Model and Personalization in ASP.NET 2.0?

 

The Provider model in ASP.NET 2.0 is based on the Provider Design Pattern that was created in the year 2002 and later implemented in the .NET Framework 2.0.

 

The Provider Model supports automatic creation of users and their respective roles by creating entries of them directly in the SQL Server (May even use MS Access and other custom data sources). So actually, this model also supports automatically creating the user table's schema.

 

The Provider model has 2 security providers in it: Membership provider and Role Provider. The membership provider saves inside it the user name (id) and corresponding passwords, whereas the Role provider stores the Roles of the users.

 

For SQL Server, the SqlMembershipProvider is used, while for MS Access, the AccessMembershipProvider is used. The Security settings may be set using the website adminstration tool. Automatically, the AccessMembershipProvider creates a Microsoft Access database file named aspnetdb.mdb inside the application's App_Data folder. This contains 10 tables.

 

ASP.NET 2.0 Personalization - Personalization allows information about visitors to be persisted on a data store so that the information can be useful to the visitor when they visit the site again. In ASP.NET 2.0, this is controlled by a Personalization API. Before the Personalization Model came into existence, the prior versions of ASP.NET used of the old Session object to take care of re-visits. Now comes the Profile object.

 

In order to use a Profile object, some settings need to be done in web.config. The example below shall explain how to use a profile object:

 

//Add this to System.Web in web.config

 

 

 

 

 

 

 

 

'In Page_Load event, add the following...

 

If Profile.FirstName <> "" Then

Panel1.Visible = False

Response.Write("Welcome Back Dear :, " & Profile.FirstName & ", " & Profile.LastName)

Else

Panel1.Visible = True

End If

 

'Here is the code how to save the profile properties in an event to save it

Profile.FirstName = txtFirstName.Text

Profile.LastName = txtLastName.Text

 

What is IIS Metabase? How to edit IIS metabase? How to backup IIS metabase file?

 

IIS Metabase - sounds like geek stuff right! What is IIS Metabase??? In the simplest words, IIS metabase is the repository of the configuration values that are set in the Internet Information Server (IIS). The IIS metabase in an XML file. It may be controlled through program or manually too.

 

In order to edit IIS metabase entries, the user needs to have administrative rights on the system. To do this, in run window, type "inetmgr". Browse to "Local Computer" and right click it. Click on "Properties". Select the "Enable Direct Metabase Edit" check box.

 

Many times, due to the existence of multiple versions of .NET framework, some settings in the IIS metabase may get affected and cause your program not to run. For such scenarios, you may take a backup of the IIS metabase XML file and recover it. To create a portable backup, open run window and type "inetmgr". Next browse to "Local Computer" and go to "All Tasks". Next, click on Backup/Restore Configuration. Next, click on "Create Backup". In the textbod box for Configuration Backup name, type a name for your backup file. Also select the encrypt backup option and type a password. To finish the process, click "OK".

 

Search for Metabase.xml file on your IIS Web Server.

 

What,s typical about a Windows process in regards to memory allocation?

 

Each process is allocated its own block of available RAM space' no process can access another process' code or data. If the process crashes' it dies alone without taking the entire OS or a bunch of other applications down.

 

Why are there five tracing levels in System.Diagnostics.TraceSwitcher?

 

The tracing dumps can be quite verbose. For applications that are constantly running you run the risk of overloading the machine and the hard drive. Five levels range from None to Verbose, allowing you to fine-tune the tracing activities.

 

Where is the output of TextWriterTraceListener redirected?

 

To the Console or a text file depending on the parameter passed to the constructor.

 

How do you debug an ASP.NET Web application?

 

Attach the aspnet_wp.exe process to the DbgClr debugger.

 

Can you change the value of a variable while debugging a C# application?

 

Yes. If you are debugging via Visual Studio.NET, just go to Immediate window.

 

What does a Web Part Consists of?

 

1. The Web Part Assembly file (.dll): which is nothing but a .dll file which contains the entire logic that you, as a developer writes for that web part. It could be a web part that contains a DataGrid and displays the number of users signed in or a simple DropDownList that populates another DropDownList within the Web Part.

2. The Web Part Description file (.dwp): This contains the default settings stored in XML format for the Web Part which can be utilized to customize and change Web Part properties. This is not mandatory though it is required while importing from a site or exporting to another site. Note that if your company has around 10,000 employees where each employee may also turn out to be your company's SharePoint site's user, then they can access say, with one particular SPS Site that has a Web Part, options to customize that particular Web Part for each of his / her sessions. That is where the WSS database tables come into play - storing various configuration and customization information. There's more but let's start off with this small step.

 

What kind of a framework does a Web Part possess?

 

A beautiful one thanks to the level of extensibility that is heavily based on the ASP.Net framework so much so that a Web Part web pages are nothing but ASP.Net web pages while Web Parts are, as mentioned above custom ASP.Net server controls. Remember that Web Parts inherit from the System.Web.UI.WebControls class.

 

. Is there a difference between a Web Part and a Server side control?

 

Yes. ASP.Net controls are added to your application during design time while Web Parts are added to an SPS Site (your application in this case) at design time or even at run-time by a user. Further, users can also customize settings during run time.

 

Where are Web Parts placed on an SPS site?

 

An SPS Site consists of Zones. Web Parts can be grouped by placed them in these zones usually called Web Part Zones.

 

What's the relation between WSS and Web Parts?

 

Nothing but pure relation. WSS is the engine for all SharePoint services, remember? Without WSS, there won't be any SPS sites and without an SPS Site, you won't have an Web Part Zone and without Zones, you can't place Web Parts. Further, WSS is central to all SharePoint services without which, there won't be any way to store user specific Web Part customization parameters, no mechanism for proper administration procedures such as backups, restores and configurations. No mechanism to support web farms and scalability and no mechanism to manage users, their roles and assignments to particular SPS site groups. WSS is the heart of the SharePoint Service engine and a Web Part is just a tiny subset of the whole picture but yet makes a powerful difference to the whole user experience.

 

Who are the users of a Web Part?

 

Developers: You need someone to expose the Microsoft.SharePoint namespace and this is where .Net developers come from. You give them the requirements and they customize your Web Part to perform the appropriate functionality.

Web Page Designers / Authors: These guys would be responsible for setting up SharePoint sites via Front Page 2003 and after developers have created their Web Parts, Web Page Designers or Authors would drag and drop required Web Part components onto the SharePoint Site.

End Users: Could be anyone looking forward to getting information or using a Web Part for a particular purpose like reading reports. The end user can further customize his Web Part during run-time.

 

What is a Web Part?

 

A Web Part, in the context of an SPS site is a component that can be customized and easily placed onto an SPS site akin to a plug'n play mechanism. Further, the end user, apart from the developer, can modify the individual properties of the Web Part. But for a developer, a Web Part is nothing but a server side ASP.Net control. The Web Part class can be found within the Microsoft.SharePoint.WebPartPages namespace which is the base class that Web Parts inherit from. The WebPartPages class inherits from the same parent class as normal ASP.Net Server controls (the System.Web.UI.WebControls class) and you therefore inherit all the properties, methods and anything else exposed by WebPart base class.

 

What is Active Directory? What is the namespace used to access the Microsoft Active Directories? What are ADSI Directories?

 

Active Directory Service Interfaces (ADSI) is a programmatic interface for Microsoft Windows Active Directory. It enables your applications to interact with diverse directories on a network, using a single interface. Visual Studio .NET and the .NET Framework make it easy to add ADSI functionality with the DirectoryEntry and DirectorySearcher components.Using ADSI, you can create applications that perform common administrative tasks, such as backing up databases, accessing printers, and administering user accounts. ADSI makes it possible for you to:

1. Log on once to work with diverse directories. The DirectoryEntry component class provides username and password properties that can be entered at runtime and communicated to the Active Directory object you are binding to.

2. Use a single application programming interface (API) to perform tasks on multiple directory systems by offering the user a variety of protocols to use. The DirectoryServices namespace provides the classes to perform most administrative functions.

3. Perform "rich querying" on directory systems. ADSI technology allows for searching for an object by specifying two query dialects: SQL and LDAP.

4. Access and use a single, hierarchical structure for administering and maintaining diverse and complicated network configurations by accessing an Active Directory tree.

5. Integrate directory information with databases such as SQL Server. The DirectoryEntry path may be used as an ADO.NET connection string provided that it is using the LDAP provider. using System.DirectoryServices;

 

What are object pooling and connection pooling and difference? Where do we set the Min and Max Pool size for connection pooling?

 

Object pooling is a COM+ service that enables you to reduce the overhead of creating each object from scratch. When an object is activated, it is pulled from the pool. When the object is deactivated, it is placed back into the pool to await the next request. You can configure object pooling by applying the ObjectPoolingAttribute attribute to a class that derives from the System.EnterpriseServices.ServicedComponent class. Object pooling lets you control the number of connections you use, as opposed to connection pooling, where you control the maximum number reached.Following are important differences between object pooling and connection pooling:

Creation. When using connection pooling, creation is on the same thread, so if there is nothing in the pool, a connection is created on your behalf. With object pooling, the pool might decide to create a new object. However, if you have already reached your maximum, it instead gives you the next available object. This is crucial behavior when it takes a long time to create an object, but you do not use it for very long.

Enforcement of minimums and maximums. This is not done in connection pooling. The maximum value in object pooling is very important when trying to scale your application. You might need to multiplex thousands of requests to just a few objects. (TPC/C benchmarks rely on this.) COM+ object pooling is identical to what is used in .NET Framework managed SQL Client connection pooling. For example, creation is on a different thread and minimums and maximums are enforced.

 

Can I run my ASP.NET 2.0 applications on my local machine to test my pages?

 

If you are using Visual Studio, you can use the ASP.NET Development Server built into Visual Studio to test your pages. The server functions as a local Web server, running ASP.NET Web pages in a manner virtually identical to how they run on a Web server. Once testing is completed you can upload your pages to our servers.

 

 

How does vs.net 2005 support biztalkserver?

 

if you install biztalk server it provides Biztalk Project in the project types like webproject, windows project, console project. We use rest of the products of the Biztalk like adapters and all those thing and use them in .net.

 

Are old projects created in Visual Studio .NET 2002 or 2003 supported in Visual Studio 2005?

 

Old projects will continue to run without change. In Visual Studio 2005, if you open a project created in Visual Studio .NET 2002 or 2003, the project is converted to the new project layout used in Visual Studio 2005. As part of the conversion, pages that use the old code-behind model are converted to use the new code-behind model. You cannot create pages using the old code-behind model in Visual Studio 2005.

 

Can I upgrade my existing ASP.NET 1.x website to ASP.NET 2.0?

 

Yes. You can either login to the Customer Control panel and select ASP.NET 2.0 for your website.

 

In ASP.Net 2.0 Login controls if you want to have your own database for login info how do you do that?

 

Create Table User with fields (UserID Primary Key, UserName,Password),Roles(RoleID Primary Key,RoleName) and UserRoles(id Primary Key, UserID Foreigh Key,RoleID Foreign Key).Populate the above tables with data. You can authenticate users based on roles from now by simply configuring web.config file.

 

How can you provide an alternating color scheme in a Repeater control?

 

AlternatingItemTemplate Like the ItemTemplate element, but rendered for every other row (alternating items) in the Repeater control. You can specify a different appearance for the AlternatingItemTemplate element by setting its style properties.

 

In what order do the events of an ASPX page execute. As a developer is it important to undertsand these events?

 

Every Page object (which your .aspx page is) has nine events, most of which you will not have to worry about in your day to day dealings with ASP.NET. The three that you will deal with the most are: Page_Init, Page_Load, Page_PreRender.

 

Describe ways of cleaning up objects.

 

There is a perfect tool provide by .net frameworks calles Garbage collector, where by meanof GC we can clean up the object and reclaim the memory. The namespace used is System.GC

the run time will maintain a service called as garbage collector.this service will take care of deallocating memory corresponding to objects.it works as a thread with least priority. When application demenads for memory the runtime will take care of setting the high priority for the garbage collector, so that it will be called for execution and memory will be released.the programmer can make a call to garbage colector by using GC class in system name space.

 

Where would you use an iHTTP Module, and what are the limitations of any approach you might take in implementing one?

 

One of ASP.NET's most useful features is the extensibility of the HTTP pipeline, the path that data takes between client and server. You can use them to extend your ASP.NET applications by adding pre- and post-processing to each HTTP request coming into your application. For example, if you wanted custom authentication facilities for your application, the best technique would be to intercept the request when it comes in and process the request in a custom HTTP module.

 

Opening popup windows with ASP.NET

 

One of the most asked question on the asp.net newsgroups is, "How can i open a popup window with ASP.NET?". The short answer is, "You can't.". Opening popups is a client side task that requires Javascript. But you can have ASP.NET emit Javascript to the client.

 

Most if not all of the server controls in ASP.NET have an Attributes.Add method that allows you to add custom attributes to the server controls. For example, you can add a client side onclick event to a hyperlink control or an onload event to a body tag. The Attributes.Add method takes 2 arguments, the first is a key which in the case of adding javascript, will be onclick, onload or other event and the second argument is the value which can also be a string or even a variable.

Make 2 new pages - default.aspx and popup.aspx. Add some text to popup.aspx. Next, add a hyperlink control to default.aspx and set its NavigateUrl property to javascript:;. Add the following code to the Page_Load subroutine.

 

Hyperlink1.Attributes.Add("onclick", "window.open('popup.aspx',null,'height=250, width=250,status= no, resizable= no, scrollbars=no, toolbar=no,location=no,menubar=no ');")

 

Preview default.aspx in your browser and when you click the hyperlink, a new popup window will open.

 

Opening a popup from a hyperlink is fine but what if you need it opened when the main page loads. Thats easy to do. First you need to add runat="server" to the body tag in default.aspx, and give it an ID of bodytag. If you are using codebehind, you'll need to declare the body tag as follows.

 

Protected WithEvents bodytag As HtmlGenericControl

 

If you are using the inline script model, you shouldnt have to declare it. The next step is add the onload event to the body tag as follows. Again it goes in the Page_Load subroutine.

 

bodytag.Attributes.Add("onload", "window.open('popup.aspx',null,'height=250, width=250,status= no, resizable= no, scrollbars=no, toolbar=no,location=no,menubar=no ');")

 

Preview the page and your popup will open when the page loads

Using the Attributes.Add method lets you add javascript events to any of the server controls. You can even specify a function name for the value parameter.

 

************************************************************

 

We can access the values from one page to another page by means of the following code.

In the First Page just add the following code,

 

Context.Items("first_name") = txtfirstname.Text

 

In the Second page just use the following code,

 

Dim name as String = CType(Context.Items("first_name"), String)

 

You will obtain the value in the Second Page now.

 

Caching Concepts

 

What is application object ?

 

Application object can used in situation where we want data to be shared across users globally.

 

What's the difference between Cache object and application object ?

 

The main difference between the Cache and Application objects is that the Cache object provides cache-specific features, such as dependencies and expiration policies.

 

How can get access to cache object ?

 

The Cache object is defined in the System.Web.Caching namespace. You can get a reference to the Cache object by using the Cache property of the HttpContext class in the System.Web namespace or by using the Cache property of the Page object.

 

What are dependencies in cache and types of dependencies ?

 

When you add an item to the cache, you can define dependency relationships that can force that item to be removed from the cache under specific activities of dependencies.Example if the cache object is dependent on file and when the file data changes you want the cache object to be update.Following are the supported dependency

 

1. File dependency :- Allows you to invalidate a specific cache item when a disk based file or files change.

 

2. Time-based expiration :- Allows you to invalidate a specific cache item depending on predefined time.

 

3. Key dependency :-Allows you to invalidate a specific cache item depending when another cached item changes.

 

Can you show a simple code showing file dependency in cache ?

 

Partial Class Default_aspx

 

Public Sub displayAnnouncement()

 

Dim announcement As String

 

If Cache("announcement") Is Nothing Then

 

Dim file As New _

 

System.IO.StreamReader _

 

(Server.MapPath("announcement.txt"))

 

announcement = file.ReadToEnd

 

file.Close()

 

Dim depends As New _

 

System.Web.Caching.CacheDependency _

 

(Server.MapPath("announcement.txt"))

 

Cache.Insert("announcement", announcement, depends)

 

End If

 

Response.Write(CType(Cache("announcement"), String))

 

End Sub

 

Private Sub Page_Init(ByVal sender As Object, ByVal e As

 

System.EventArgs) Handles Me.Init

 

displayAnnouncement()

 

End Sub

 

End Class

 

What is Cache Callback in Cache ?

 

Cache object is dependent on its dependencies example file based , time based etc.Cache items remove the object when cache dependencies change.ASP.NET provides capability to execute a callback method when that item is removed from cache.

 

What is scavenging ?

 

When server running your ASP.NET application runs low on memory resources , items are removed from cache depending on cache item priority.cache item priority is set when you add item to cache.BY setting the cache item priority controls which items scavenging is removed first.

 

What are different types of caching using cache object of ASP.NET?

 

You can use two types of output caching to cache information that is to be transmitted to and displayed in a Web browser:

 

1. Page Output Caching

 

Page output caching adds the response of page to cache object.Later when page is requested page is displayed from cache rather than creating the page object and displaying it.Page output caching is good if the site is fairly static.

 

2. Page Fragment Caching

 

If parts of the page are changing, you can wrap the static sections as user controls and cache the user controls using pagefragment caching.

 

How can you cache different version of same page using ASP.NET cache object ?

 

Output cache functionality is achieved by using "OutputCache" attribute on ASP.NET page header.Below is the syntax

 

<%@ OutputCache Duration="20" Location="Server" VaryByParam="state" VaryByCustom="minorversion" VaryByHeader="Accept-Language"%>

 

(a) VaryByParam :- Caches different version depending on input parameters send through HTTP POST/GET.

 

(b) VaryByHeader:- Caches different version depending on the contents of the page header.

 

(c) VaryByCustom:-Lets you customize the way the cache handles page variations by declaring the attribute and overriding the GetVaryByCustomString handler.

 

(d) VaryByControl:-Caches different versions of a user control based on the value of properties of ASP objects in the control.

 

How will implement Page Fragment Caching ?

 

Page fragment caching involves the caching of a fragment of the page, rather than the entire page. When portions of the page need to be dynamically created for each user request this is best method as compared to page caching.You can wrap Web Forms user control and cache the control so that these portions of the page don't need to be recreated each time.

 

What are ASP.NET session and compare ASP.NET session with classic ASP session variables?

 

ASP.NET session caches per user session state.It basically uses "HttpSessionState" class. Following are the limitations in classic ASP sessions :-

 

(a) ASP session state is dependent on IIS process very heavily.So if IIS restarts ASP session variables are also recycled.ASP.NET session can be independent of the hosting environment thus ASP.NET session can maintained even if IIS reboots.

 

(b) ASP session state has no inherent solution to work with Web Farms.ASP.NET session can be stored in state server and SQL SERVER which can support multiple server.

 

(c) ASP session only functions when browser supports cookies.ASP.NET session can be used with browser side cookies or independent of it.

 

Which various modes of storing ASP.NET session ?

 

(a) InProc:- In this mode Session state is stored in the memory space of the Aspnet_wp.exe process.This is the default setting.If the IIS reboots or web application restarts then session state is lost.

 

(b) StateServer:-In this mode Session state is serialized and stored in a separate process Aspnet_state.exe); therefore, the state can be stored on a separate computer(a state server).

 

(c) SQL SERVER:- In this mode Session state is serialized and stored in a SQL Server database. Session state can be specified in <sessionState> element of application configuration file.Using State Server and SQL SERVER session state can be shared across web farms but note this comes at speed cost as ASP.NET needs to serialize and deserialize data over network again and again.

 

Is Session_End event supported in all session modes ?

 

Session_End event occurs only in "Inproc mode"."State Server" and "SQL SERVER" do not have Session_End event.

 

What are the precautions you will take in order that StateServer Mode work properly ?

 

Following are the things to remember so that StateServer Mode works properly :-

 

(a) StateServer mode session data is stored in a different process so you must ensure that your objects are serializable.

 

(b) <machineKey> elements in Web.config should be indentical across all servers.So this ensures that encryption format is same across all computers.

 

(c) IIS metabase (\LM\W3SVC\2) must be identical across all servers in that farm.

 

What are the precautions you will take in order that SQLSERVER Mode work properly ?

 

Following are the things to remember so that SQLSERVER Mode works properly :-

 

(a) SQLSERVER mode session data is stored in a different process so you must ensure that your objects are serializable.

 

(b) IIS metabase (\LM\W3SVC\2) must be indentical across all servers in that farm.

 

(c) By default Session objects are stored in "Tempdb" , you can configure it store outside "TempDB" by running microsoft provided SQL script.

 

Note :- "TempDB" database is re-created after SQL SERVER computer reboot.If you want to maintain session state with every reboot best is to run SQL Script and store session objects outside "TempDB" database.

 

Where do you specify session state mode in ASP.NET ?

 

<sessionState mode="SQLServer" stateConnectionString="tcpip=192.168.1.1:42424" sqlConnectionString="data source=192.168.1.1; Integrated Security=SSPI" cookieless="false" timeout="20"

 

/>

 

Above is sample session state mode specified for SQL SERVER.

 

What are the other ways you can maintain state ?

 

Other than session variables you can use the following technique to store state :

 

1. Hidden fields

 

2. View state

 

3. Hidden frames

 

4. Cookies

 

5. Query strings

 

What are benefits and Limitation of using Hidden fields ?

 

Following are the benefits of using Hidden fields :-

 

1. They are simple to implement.

 

2. As data is cached on client side they work with Web Farms.

 

3. All browsers support hidden field.

 

4. No server resources are required.

 

Following are limitations of Hidden field :-

 

1.They can be tampered creating a security hole.

 

2. Page performance decreases if you store large data , as the data is stored in pages itself.

 

3. Hidden fields do not support rich structures as HTML hidden fields are only single valued. Then you have to work around with delimiters etc to handle complex structures.

 

Below is how you will actually implement hidden field in a project

 

<input id="HiddenValue" type="hidden" value="Initial Value" runat="server"NAME="HiddenValue">

 

What is ViewState ?

 

Viewstate is a built-in structure for automatically retaining values among multiple requests for the same page. The view state is internally maintained as a hidden field on the page but is hashed, providing greater security than developer-implemented hidden fields do.

 

Do performance vary for viewstate according to User controls ?

 

Performance of view state varies depending on the type of server control to which it is applied. Label, TextBox, CheckBox, RadioButton, and HyperLink are server controls that perform well with ViewState. DropDownList, ListBox, DataGrid, and DataList suffer from poor performance because of their size and the large amounts of data making roundtrips to the server.

 

What are benefits and Limitation of using Viewstate for state management?

 

Following are the benefits of using Viewstate :-

 

1. No server resources are required because state is contained in a structure in the page code.

 

2. Simplicity.

 

3. States are retained automatically.

 

4. The values in view state are hashed, compressed, and encoded, thus representing a higher state of security than hidden fields.

 

5. View state is good for caching data in Web farm configurations because the data is cached on the client.

 

Following are limitation of using Viewstate:-

 

1. Page loading and posting performance decreases when large values are stored because view state is stored in the page.

 

2. Although view state stores data in a hashed format, it can still be tampered with because it is stored in a hidden field on the page. The information in the hidden field can also be seen if the page output source is viewed directly, creating a potential security risk.

 

Below is sample of storing values in view state.

 

this.ViewState["EnterTime"] = DateTime.Now.ToString();

 

How an you use Hidden frames to cache client data ?

 

This technique is implemented by creating a Hidden frame in page which will contain your data to be cached.

 

<FRAMESET cols="100%,*,*">

 

<FRAMESET rows="100%">

 

<FRAME src="data_of_frame1.html"></FRAMESET>

 

<FRAME src="data_of_hidden_frame.html">

 

<FRAME src="data_of_hidden_frame.html" frameborder="0" noresize scrolling="yes">

 

</FRAMESET>

 

Above is a sample of hidden frames where the first frame "data_of_frame1.html" is visible and the remaining frames are hidden by giving whole col section to first frame. See allocation where 100 % is allocated to first frame and remaining frames thus remain hidden.

 

What are benefits and Limitation of using Hidden frames?

 

Following are the benefits of using hidden frames:

 

1. You can cache more than one data field.

 

2. The ability to cache and access data items stored in different hidden forms.

 

3. The ability to access JScript® variable values stored in different frames if they come from the same site.

 

The limitations of using hidden frames are:

 

1. Hidden frames are not supported on all browsers.

 

2. Hidden frames data and be tampered thus creating security hole.

 

What are benefits and Limitation of using Cookies?

 

Following are benefits of using cookies for state management :-

 

1. No server resources are required as they are stored in client.

 

2. They are light weight and simple to use

 

Following are limitation of using cookies :-

 

1. Most browsers place a 4096-byte limit on the size of a cookie,although support for 8192-byte cookies is becoming more common in the new browser and client-device versions available today.

 

2. Some users disable their browser or client device's ability to receive cookies, thereby limiting the use of cookies.

 

3. Cookies can be tampered and thus creating a security hole.

 

4. Cookies can expire thus leading to inconsistency.

 

Below is sample code of implementing cookies

 

Request.Cookies.Add(New HttpCookie("name", "user1"))

 

What is Query String and What are benefits and Limitation of using Query Strings?

 

A query string is information sent to the server appended to the end of a page URL.

 

Following are the benefits of using query string for state management:-

 

1. No server resources are required. The query string is contained in the HTTP request for a specific URL.

 

2. All browsers support query strings.

 

Following are limitations of query string :-

 

1. Query string data is directly visible to user thus leading to security problems.-

 

2. Most browsers and client devices impose a 255-character limit on URL length.

 

Below is a sample "Login" query string passed in URL

 

http://www.querystring.com/login.asp?login=testing.This querystring data can then be requested later by using Request.QueryString("login").

 

Redirecting User to Login Page After Session Timeouts

In most of the applications you might come across the situation where you need to redirect the user to login page after session timeouts. It is simple, if you want to redirect user to login page when the user submits the page after session timeout. You got the control in server, you can check for session timeout. If that is true, then you can redirect the user to any page you want. If you implemented Authentication like Forms authentication or Passport authentication in your applications. Then this is done automatically when the user resubmits the page after session timeouts.

But the requirement is such that you want to redirect the user immediately after timeout to login page before the user submits the page. In this article, I am going to explain how we can achieve this in ASP.NET.Before we see how to redirect the the user to login page after session timeout, we will see how to refresh any page after certain intervals. This will help me to clearly explain how to play with page redirection from client.

Refreshing any page after certain interval

For refreshing any page after certain interval, you need to use client side script only. You cant do this in server side, The reason being that the page has been served to the client, end of request. The web is stateless; until the user comes back and initiates another request the server can't do anything. So we need to do this refreshing activity from client side only. There are two ways to achieve this,

1. Using Window.setTimeout method

2. Using Meta Tag - Refresh.

Using Window.setTimeout method:

DHTML Window object has a method called "setTimeout" which evaluates an expression after a specified number of milliseconds has elapsed. With the help of this method, you can run the client side script window.location.href="somepage" to redirect page in the current window. SetTimeout accepts three parameters.

 

vCode

           

 

Required. Variant that specifies the function pointer or string that indicates the code to be executed when the specified interval has elapsed.

 

iMilliSeconds

           

 

Required. Integer that specifies the number of milliseconds.

 

sLanguage

           

 

Optional. String that specifies one of the following values:

 

JScript

           

 

Language is JScript.

 

VBScript

           

 

Language is VBScript.

 

JavaScript

           

 

Language is JavaScript.

 

You need to call this method in body load and start the timer( by calling setTimeout method). This timer will elapse depending upon the second parameter for this method. When it is elapsed, it will fire the script which is given as first parameter. So you need to add this to the body element onload method. For adding client side event to body tag in asp.net you need to follow this methos.

1. Declare the body tag in html window as server control by specifing runat attribute and give an id to that tag.

<body runat="server" id= "body">< /P>< /FONT>

2. In the code behind, declare this element as htmlgenericcontrol like this.

Protected WithEvents body As System.Web.UI.HtmlControls.HtmlGenericControl

3. Finally add the following code in your page_load event handler, this will add the client side handler for body tag.

body.Attributes.Add("onLoad", "window.setTimeout(""window.location.href='<somepage>.aspx'"",5000);")

This method will refresh the page to the specified location after 5 secs. The disadvantage of this method is, this might not work in some lower end browsers. So you need to go for other method i.e. by using Meta Tags.

Using Meta Tag - Refresh

Another way for refreshing the page after certain interval is by using meta tag - Refresh. This tag specifies a delay in seconds before the browser automatically reloads the document. Optionally, specifies an alternative URL to load. Example

<META HTTP-EQUIV="Refresh" CONTENT="3;URL=http://www.some.org/some.html">

In ASP.NET, you can add headers in code behind using this method.

Response.AppendHeader("Refresh", "10; URL=.aspx")

This method will reload the current window after interval mentioned in the second parameter to the page which is mentioned as URL to refresh. In this case page will be refreshed after 10 seconds.

Redirecting User To Login Page after Session Timeouts.

Redirecting user to login page after session timeout is similar to refreshing the page after certain intervals method. Only thing which will differ is that calculating time after which the page has to be redirected. Hence time can be calculated using Session.timeout property which will give us session timeout value for that session. Add some grace timings to that value and redirect the user to the login page automatically.

Using Window.setTimeout method

body.Attributes.Add("onLoad", "window.setTimeout(""window.location.href='login.aspx'""," & (Session.Timeout * 60 * 1000) + 10000 & ");")

Using Meta Tag - Refresh

Response.AppendHeader("Refresh", Convert.ToString((Session.Timeout * 60) + 10) & "; URL=Login.aspx")

Both these methods will redirect the user to login page after session timeout + 10 seconds. This is how you can redirect the user to login page after session timeout without user interaction

 

 

 

Search from any Web page with powerful protection. Get the FREE Windows Live Toolbar Today! Try it now!

 

How fill drop down list in asp.net

 

Dim myconnection As SqlConnection

Dim myda As SqlDataAdapter

Dim ds As DataSet

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

myconnection = New SqlConnection("Server=localhost;uid=sa;password=;database=northwind;")

myda = New SqlDataAdapter("Select * from CategoryTable ", myconnection)

ds = New DataSet

myda.Fill(ds, "AllTables")

DropDownList1.DataSource = ds

DropDownList1.DataSource = ds.Tables(0)

DropDownList1.DataTextField = ds.Tables(0).Columns("CategoryName").ColumnName.ToString()

DropDownList1.DataValueField = ds.Tables(0).Columns("CategoryId").ColumnName.ToString()

DropDownList1.DataBind()

Dim i As Integer

For i = 0 To DropDownList1.Items.Count - 1

DropDownList1.Items(i).Attributes.Add("style", "color:" + ds.Tables(0).Rows(i)"CategoryColor").ToString())

Next

End Sub

 

How to write to an XML file

 

<%@Page Language="VB" Debug="True" %>

<%@Import Namespace="System.XML" %>

<%@ Import Namespace="System.IO" %>

 

<script language="vb" runat="server">

Sub Page_Load()

Dim strCurrentPath As String = Request.PhysicalPath

Dim strXMLPath As String = Left(strCurrentPath, InStrRev(strCurrentPath, "\")) & "members3.xml"

Dim objXMLWriter As XmlTextWriter

Try

objXMLWriter = New XmlTextWriter(strXMLPath, Nothing)

outDocURL.innerHTML = "Writing to file: <b>" & strXMLPath & "</b>"

Catch objError As Exception

outError.innerHTML = "<b>* Error while accessing document</b>.<br />" & objError.Message & "<br />" & objError.Source

Exit Sub

End Try

objXMLWriter.Formatting = Formatting.Indented

objXMLWriter.Indentation = 3

objXMLWriter.WriteStartDocument()

objXMLWriter.WriteComment("Created on " & Now())

objXMLWriter.WriteStartElement("members")

objXMLWriter.WriteStartElement("member")

objXMLWriter.WriteAttributeString("position", "regular")

Dim intYears As Integer = 4

objXMLWriter.WriteAttributeString("years", intYears.ToString("G"))

objXMLWriter.WriteElementString("Address", "2374 Ash St.")

Dim datBirthday As DateTime = #03/05/2000#

objXMLWriter.WriteElementString("birthday", datBirthday.ToString("yyyy-MM-dd"))

Dim intContributions As Integer = 23443

objXMLWriter.WriteElementString("contributions", intContributions.ToString("G"))

Dim blnLocal As Boolean = True

objXMLWriter.WriteElementString("local", blnLocal.ToString())

objXMLWriter.WriteEndElement()

objXMLWriter.WriteEndElement()

objXMLWriter.Flush()

objXMLWriter.Close()

Dim strXMLResult As String

Dim objSR As StreamReader = File.OpenText(strXMLPath)

strXMLResult = objSR.ReadToEnd()

objSR.Close

objSR = Nothing

outResults.innerHTML = "<pre>" & Server.HtmlEncode(strXMLResult) & "<pre>"

End Sub

</script>

 

 

<html>

<body bgcolor="#ffffff">

 

<div id="outDocURL" runat="server"></div>

<div id="outError" runat="server"> </div>

<div id="outResults" runat="server"></div>

 

</body>

</html>

 

 

Windows Live Spaces is here! It's easy to create your own personal Web site. Check it out!

 

Save and retrieve image from sql server 2000 in asp.net

 

Imports System.Drawing

 

Imports System.Data

 

Imports System.IO

 

Imports System.Drawing.Imaging

 

Private Sub btnUploadImage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUploadImage.Click

 

Dim intImgLen As Integer = MyFile.PostedFile.ContentLength

 

Dim picbyte(intImgLen) As Byte

 

MyFile.PostedFile.InputStream.Read(picbyte, 0, intImgLen)

 

SqlCon = New SqlConnection("server=172.16.1.22;uid=sa;pwd=;database=test;")

 

SqlCon.Open()

 

SSQL = "Insert into ImageTable (Image) values(@pic)"

 

sCommand = New SqlCommand(SSQL, SqlCon)

 

sCommand.Parameters.Add("@pic", picbyte)

 

sCommand.ExecuteNonQuery()

 

SqlCon.Close()

 

End Sub

 

Private Sub btnFetchImage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFetchImage.Click

 

Dim imag() As Byte

 

Dim Img As Image

 

SqlCon = New SqlConnection("server=172.16.1.22;uid=sa;pwd=;database=test;")

 

SqlCon.Open()

 

SSQL = "select Image from ImageTable"

 

sCommand = New SqlCommand(SSQL, SqlCon)

 

SReader = sCommand.ExecuteReader()

 

While (SReader.Read())

 

Dim byt As Byte()

 

byt = SReader.Item("Image")

 

'Dim bmp As New Bitmap(New System.IO.MemoryStream(byt))

 

'Img = bmp

 

Response.BinaryWrite(byt)

 

End While

 

SqlCon.Close()

 

End Sub

 

 

Get the new Windows Live Messenger! Try it!

 

Send a mail with attachment in asp.net

 

Imports System.Web.Mail

 

Dim objMailAttachment As MailAttachment

 

Dim objMailMessage As MailMessage

 

objMailAttachment = New MailAttachment("C:\YServer.txt")

 

objMailMessage = New MailMessage

 

objMailMessage.From = "jmaneesh@sify.com"

 

objMailMessage.To = "jmaneesh@gmail.com"

 

objMailMessage.Subject = "Mail Attachment"

 

objMailMessage.Body = "check mail attachment"

 

objMailMessage.Attachments.Add(objMailAttachment)

 

SmtpMail.SmtpServer = "172.0.0.0"

 

SmtpMail.Send(objMailMessage)

 

 

 

Windows Live Spaces is here! It's easy to create your own personal Web site. Check it out!

 

Upload a file in asp.net

 

Add the enctype="multipart/form-data" name-value attribute to the <form> tag as follows:

 

<form id="Form1" method="post" enctype="multipart/form-data" runat="server">

 

Private Sub btnUpload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpload.Click

 

If Not MyFile.PostedFile Is Nothing And MyFile.PostedFile.ContentLength > 0 Then

 

Dim fn As String = System.IO.Path.GetFileName(MyFile.PostedFile.FileName)

 

Dim strSaveLocation As String = Server.MapPath("Upload") & "\" & fn

 

Dim index = fn.LastIndexOfAny(".")

 

Dim GetExtension = fn.Substring(index + 1)

 

If (UCase(GetExtension) = "TXT") Or (UCase(GetExtension) = "DOC") Then

 

MyFile.PostedFile.SaveAs(strSaveLocation)

 

lblMessage.Text = "File Has Been Uploaded Successfully."

 

Else

 

lblMessage.Text = "Incorrect File format."

 

End If

 

Else

 

lblMessage.Text = "please select a file to upload."

 

End If

 

End Sub

 

 

Call friends with PC-to-PC calling -- FREE Try it now!

 

ASP.NET 2.0 - FAQ

 

· Why is there no DataGrid control on the Toolbox?

 

The DataGrid control has been superseded by the GridView control, which can do everything the DataGrid control does and more. The GridView control features automatic data binding; auto-generation of buttons for selecting, editing, and deleting; automatic sorting; and automatic paging. There is full backward compatibility for the DataGrid control, and pages that use the DataGrid will continue to work as they did in version 1.0 of ASP.NET.

 

· Can I still use the DataList and Repeater controls?

 

Absolutely. You can use them the way you always have. But note that the controls have been enhanced to be able to interact with data source controls and to use automatic data binding. For example, you can bind a DataList or Repeater control to a SqlDataSource control instead of writing ADO.NET code to access the database.

 

· What's the difference between login controls and Forms authentication?

 

Login controls are an easy way to implement Forms authentication without having to write any code. For example, the Login control performs the same functions you would normally perform when using the FormsAuthentication class — prompt for user credentials, validate them, and issue the authentication ticket — but with all the functionality wrapped in a control that you can just drag from the Toolbox in Visual Studio. Under the covers, the login control uses the FormsAuthentication class (for example, to issue the ticked) and ASP.NET membership (to validate the credentials). Naturally, you can still use Forms authentication yourself, and applications you have that currently use it will continue to run.

Configuring ASP.NET 2.0

 

· How is ASP.NET configuration data formatted?

 

ASP.NET configuration data is encoded in XML and stored as plaintext files. You can access these files programmatically by using administration tools or by using a text editor

 

· Where are the ASP.NET configuration files stored?

 

System-wide configuration settings and some ASP.NET schema settings are stored in a file named Machine.config, which is located in the %SystemRoot%\Microsoft .NET\Framework\versionNumber\CONFIG directory. This directory also contains other default settings for ASP.NET Web applications in a file that is referred to as the root Web.config file. ASP.NET configuration files for individual Web sites and applications, which are also named Web.config files, can be stored in any Web site root directory, application root directory, application subdirectory, or all of these.

 

· How are the ASP.NET configuration files related to the Internet Information Services (IIS) configuration file (the IIS metabase)?

 

In IIS versions 6.0 and earlier, the ASP.NET configuration system redirects any IIS-specific settings that it controls. The ASP.NET configuration system then configures IIS for you by automatically editing the IIS metabase. For information about the IIS metabase.

 

· I used the ASP.NET configuration system to restrict access to my ASP.NET application, but anonymous users can still view some of my files. Why is that?

 

The features of the ASP.NET configuration system only apply to ASP.NET resources. For example, Forms Authentication only restricts access to ASP.NET files, not to static files or ASP (classic) files unless those resources are mapped to ASP.NET file name extensions. Use the configuration features of IIS to configure non-ASP.NET resources.

 

· Since there can be multiple ASP.NET configuration files on one computer, how does ASP.NET configuration handle inheritance?

 

ASP.NET integrates the settings in configuration files (the Machine.config and Web.config files) into a single inheritance hierarchy. With a few exceptions, you can place a Web.config file wherever you need to override the configuration settings that are inherited from a configuration file located at a higher level in the hierarchy.

 

· How does ASP.NET consolidate the settings in all of the configuration files?

 

At run time, ASP.NET reads the settings in the Machine.config file and all of the Web.config files and then assembles a cache of the settings for each valid URL in each application on the server.

 

· What happens when a configuration setting changes during run time?

 

ASP.NET invalidates the existing cache and assembles a new cache. Then ASP.NET automatically restarts the application to apply the changes.

 

· Can I lock a configuration setting so that a Web.config file that appears lower in the hierarchy cannot override it?

 

Yes. By setting the location element's Override attribute to false, you can lock a specific setting so that it does not inherit settings from below.

 

· Can I configure specific folders directly?

 

Yes. By using the location element in a configuration file that is located higher in the configuration hierarchy, you can configure the attributes of individual resources, such as the application directories under a Web site or application subdirectories. This is useful in hosting environments for specifying configuration settings in a machine-level configuration file that apply to individual Web sites.

 

· How can I get programmatic access to ASP.NET configuration settings?

 

You can read, create, or modify configuration settings from within an ASP.NET application by using the ASP.NET management API. You can develop your own applications including Web applications, console applications, and scripts that use the management API.

 

· How can I get programmatic access to IIS configuration settings?

 

You can use ADSI, WMI, or COM interfaces to configure IIS programmatically.

 

· How are ASP.NET configuration files secured against unauthorized access?

 

ASP.NET configures IIS to deny access to any user that requests access to the Machine.config or Web.config files.

 

· What are the limitations when configuring ASP.NET by using the ASP.NET MMC snap-in?

 

The ASP.NET MMC snap-in allows you to set ASP.NET configuration at all levels, but on the local computer only.

 

· Can I configure ASP.NET Web sites and applications remotely?

 

Yes. You can use the Web Site Administration Tool to configure remote Web sites and applications by using a Web browser.

 

· Can I configure ASP.NET by directly editing the Machine.config and Web.config files?

 

Yes. You can use any text editor or XML editor to edit the ASP.NET configuration files directly. However, consider using one of the tools mentioned in the previous questions to edit ASP.NET configuration because those tools often ensure XML validation.

 

· Can I configure ASP.NET by directly editing the IIS metabase file?

 

The IIS 6.0 metabase is stored in an XML-formatted file called Metabase.xml. You can configure IIS to allow the metabase to be edited directly, but not all of the ASP.NET configuration settings are available in the IIS metabase. It is best to configure ASP.NET features by using the ASP.NET configuration system.

 

· What tools can I use to edit the IIS metabase?

 

You can use the IIS Manager snap-in for the MMC. For information about common administrative tasks for ASP.NET developers.

Comments

  1. Nice Post Mohan. Keep up the good work. Although i would like to mention that ASP.NET Cache can really get a boost by using external Caching Solution like NCaChe. It is a distributed ASP.NET Cache which can boost your application performance and scalability. It also has a free version Called NCache Express, good for 2 server farms.

    ReplyDelete

Post a Comment

Popular Posts

DOT NET Interview Questions with Answers

When not to use Design Patterns? Do not use design patterns in any of the following situations. • When the software being designed would not change with time. • When the requirements of the source code of the application are unique. If any of the above applies in the current software design, there is no need to apply design patterns in the current design and increase unnecessary complexity in the design. When to use Design Patterns? Design Patterns are particularly useful in one of the following scenarios. • When the software application would change in due course of time. • When the application contains source code that involves object creation and event notification. Benefits of Design Patterns: The following are some of the major advantages of using Design Patterns in software development. • Flexibility • Adaptability to change • Reusability What are Design Patterns? A Design Pattern essentially consists of a problem in a software design and a solutio

Free Softwares 09 July 09

JDownloader JDownloader, open source and platform independent, can help download files from file hosters like Rapidshare.com, Megaupload.com and others. JDownloader can be used by both kinds of users - those who have a premium account and those who don't pay. Features: Support for many file hosting sites, decrypt plug-ins for many services. e.g. sj.org, UCMS, WordPress, skips the limits of Filehosting websites, downloads in multiple paralell streams, download with multiple connections, captcha recognition, automatical file extraction, Can download Youtube, Vimeo, clipfish video, and Mp3 files; 24-hour support, integrates with Firefox, no installation needed, and more. The 15.6 MB JDownloader, v.0.6.193, cross-platform - works on Windows, Linux and Mac OS X, can be downloaded at http://jdownloader.en.softonic.com/download Runs on Java 1.5 or higher. jGnash jGnash is a free personal finance manager with many features available in commercial versions. Main Features

PDF Converter Ultimate - Awesome Converter

PDF Converter Ultimate  Convert your documents to PDF, and PDF documents to Word, Excel, JPG, and more, right on your Android device. Conversions are accurate and very fast, layout is preserved, and best-on-market OCR engines will take care of your scanned files. Easy to use app, and amazing conversion quality makes this app the ultimate converter for your phone. You can convert files from your phone, or files from your favorite cloud services directly within our app. Files are being converted by our powerful servers, and after conversion is done, result is downloaded to your device and files are being deleted from our servers. This also means the app won't burden your processor or RAM, nor it will drain your battery. • Conversions are fast and accurate • Scanned and complex documents are converted as well  • Immediate conversions for free users • Several conversion types available depending on the file format needed • No limit on file size or number of files you can co

Free softwares

AutoHotkey AutoHotkey is a free, open-source utility for Windows. automate almost anything by sending keystrokes and mouse clicks. A tutorial at http://www.autohotkey.com/docs/Tutorial.htm  The 1704 KB AutoHotkey v.1.0.44.08 can be downloaded at http://www.autohotkey.com/download/AutoHotkeyInstall.exe (Source: Linda Bee) Advanced WindowsCare Advanced WindowsCare's Personal Edition and Professional editions promise a new way to maintain your computer with just a click each day. No need to be an IT expert or geek! You are invited to try out the v2 Beta 3.02 (July 27, '06) at  https://www.iobit.com/en/advancedsystemcarefree.php (Source: FreewareFiles Express) ShortText "ShortText.com: A brilliant idea and a great find say BBC World. What is ShortText? It's a convenient way to create your own instant webpage , for free. Just paste a block of text into the text editor on the  site to receive a custom URL. Now ShortText is not there. Alternatives are 

Privado.com - A Private Search Engine

https://www.privado.com/ Your searches should be private. We make sure they really are.  Private Search in Action  We don’t track you  We don’t store your searches in any identifiable way  We don’t store your IP address in our services Your privacy is important.  There are no traces of your activities and personal identity in our servers.  You can learn more about privacy in our blog  We don't like cookies!   https://www.privado.com/

Contact Form

Name

Email *

Message *