Wednesday, November 14, 2007

Dot Net Interview Questions - Part 9

  1. How do you implement postback with a text box? What is postback and usestate?
    Make AutoPostBack property to true
  2. How can you debug an ASP page, without touching the code?
  3. What is SQL injection?
    An SQL injection attack "injects" or manipulates SQL code by adding unexpected SQL to a query.
    Many web pages take parameters from web user, and make SQL query to the database. Take for instance when a user login, web page that user name and password and make SQL query to the database to check if a user has valid name and password.
    Username: ' or 1=1 ---
    Password: [Empty]
    This would execute the following query against the users table:
    select count(*) from users where userName='' or 1=1 --' and userPass=''
  4. How can u handle Exceptions in Asp.Net?
  5. How can u handle Un Managed Code Exceptions in ASP.Net?
  6. Asp.net - How to find last error which occurred?
    A: Server.GetLastError();
    [C#]
    Exception LastError;
    String ErrMessage;
    LastError = Server.GetLastError();
    if (LastError != null)
    ErrMessage = LastError.Message;
    else
    ErrMessage = "No Errors";
    Response.Write("Last Error = " + ErrMessage);

7. How to do Caching in ASP?
A: <%@ OutputCache Duration="60" VaryByParam="None" %>

VaryByParam value

Description

none

One version of page cached (only raw GET)

*

n versions of page cached based on query string and/or POST body

v1

n versions of page cached based on value of v1 variable in query string or POST body

v1;v2

n versions of page cached based on value of v1 and v2 variables in query string or POST body

<%@ OutputCache Duration="60" VaryByParam="none" %>
<%@ OutputCache Duration="60" VaryByParam="*" %>
<%@ OutputCache Duration="60" VaryByParam="name;age" %>

The OutputCache directive supports several other cache varying options

    • VaryByHeader - maintain separate cache entry for header string changes (UserAgent, UserLanguage, etc.)
    • VaryByControl - for user controls, maintain separate cache entry for properties of a user control
    • VaryByCustom - can specify separate cache entries for browser types and version or provide a custom GetVaryByCustomString method in HttpApplicationderived class
  1. What is the Global ASA(X) File?

  1. Any alternative to avoid name collisions other then Namespaces.
    A scenario that two namespaces named N1 and N2 are there both having the same class say A. now in another class i ve written
    using N1;using N2;
    and i am instantiating class A in this class. Then how will u avoid name collisions?
    Ans: using alias
    Eg:
    using MyAlias = MyCompany.Proj.Nested;
  2. Which is the namespace used to write error message in event Log File?
  3. What are the page level transaction and class level transaction?
  4. What are different transaction options?
  5. What is the namespace for encryption?
  6. What is the difference between application and cache variables?
  7. What is the difference between control and component?
  8. You ve defined one page_load event in aspx page and same page_load event in code behind how will prog run?
  9. Where would you use an IHttpModule, and what are the limitations of any approach you might take in implementing one?
  10. Can you edit data in the Repeater control? Which template must you provide, in order to display data in a Repeater control? How can you provide an alternating color scheme in a Repeater control? What property must you set, and what method must you call in your code, in order to bind the data from some data source to the Repeater control?
  11. What is the use of web.config? Difference between machine.config and Web.config?
    ASP.NET configuration files are XML-based text files--each named web.config--that can appear in any directory on an ASP.NET Web application server. Each web.config file applies configuration settings to the directory it is located in and to all virtual child directories beneath it. Settings in child directories can optionally override or modify settings specified in parent directories. The root configuration file--WinNT\Microsoft.NET\Framework\\config\machine.config—provides default configuration settings for the entire machine. ASP.NET configures IIS to prevent direct browser access to web.config
    files to ensure that their values cannot become public (attempts to access them will cause ASP.NET to return 403: Access Forbidden).
    At run time ASP.NET uses these web.config configuration files to hierarchically compute a unique collection of settings for each incoming URL target request (these settings are calculated only once and then cached across subsequent requests; ASP.NET automatically watches for file changes and will invalidate the cache if any of the configuration files change).
What is the use of sessionstate tag in the web.config file?
Configuring session state:
Session state features can be configured via the section in a web.config file. To double the default timeout of 20 minutes, you can add the following to the web.config file of an application:

No comments: