Showing posts with label XML. Show all posts
Showing posts with label XML. Show all posts

Friday, July 25, 2014

ASP.NET Web.config related Interview Questions

1). What is web.config file in asp.net?
Web.config is the main settings and configuration file for an ASP.NET web application. The file is an xml document that defines configuration information regarding the web application.This file stores the information about how the web application will act. 

2). Does web.config file case-sensitive?
Yes.

3). Web.config file is stored in which form?
Web.config files are stored in XML format.

4). Can one directory contain multiple web.config files?
No. One directory can contain only one file.

5). Can you tell the location of the root web.confit file from which all web.config file inherit ?
All the Web.config files inherit the root Web.config file available at the following location systemroot\Microsoft.NET\Framework\versionNumber\CONFIG\Web.config


6). What is the root tag of web.config file ?
<configuration> tag is the root element of the Web.config file under which it has all the remaining sub elements.

7). What is the use of customErrors tag in web.config file ?
CustomErrors tag provides information about custom error messages for an ASP.NET application. The customErrors element can be defined at any level in the application file hierarchy.
Code:
<customErrors defaultRedirect ="Error.aspx" mode ="Off">
   <error statusCode ="401" redirect ="Unauthorized.aspx"/>
</customErrors>

The customErrors section consists of defaultRedirect and mode attributes which specify the default redirect page and the on/off mode respectively.
The subsection of customErrors section allows redirecting to specified page depending on the error status code.
400 Bad Request
401 Unauthorized
404 Not Found
408 Request Timeout

8). Can you describe the funcnalitity of <httpHandlers> tab in web.config?
HttpHandler is a code that executes when an http request for a specific resource is made to the server. For example, request an .aspx page the ASP.NET page handler is executed, similarly if an .asmx file is requested, the ASP.NET service handler is executed. An HTTP Handler is a component that handles the ASP.NET requests at a lower level than ASP.NET is capable of handling.

9). What is authentication tag/section in web.config?
ASP.NET implements additional authentication schemes using authentication providers, which are separate from and apply only after the IIS authentication schemes. ASP.NET supports the following authentication providers:
Windows (default)
Forms
Passport
None
To enable an authentication provider for an ASP.NET application, use the authentication element in either machine.config or Web.config as follows:
Code:
<system.web>
   <!-- mode=[Windows|Forms|Passport|None] -->
   <authentication mode="Windows" />
</system.web>


10). For which purpose you use <appSettings> tag?
appSettings tag helps us to store the application settings information like connection strings, file paths, URLs, port numbers, custom key value pairs, etc.
Ex:-
Code:
<appSettings>
    <add key="ConString" value="Data Srouce=....."/>
</appSettings>


11). What is the use of connectionStrings tag?
<connectionStrings> is the most common section of web.config file which allows you to store multiple connection strings that are used in the application.
Code:
<connectionStrings>
    <add name ="ConString" connectionString ="Initial Catalog = abc;
        Data Source =localhost; Integrated Security = true"/>
</connectionStrings>


12). Can you write down the C# code for reading connection string which is defined in web.config?
Code:
string cnn = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;

Wednesday, October 10, 2012

How Dynamically Make and show ASP.NET Menu Items using XML Datasource


How Dynamically Make and show ASP.NET Menu Items using XML Datasource

i want to make asp.net menu dynamically using ms sql 2005 db   i could just find these codes for getting items in the hierarchical schema,any one knows how to bind it to asp.net menu using XML datasource? 
Code to be put in ASPX file....

<asp:Menu ID="Menu1" runat="server" MaximumDynamicDisplayLevels="4" StaticDisplayLevels="2"
            DynamicHorizontalOffset="1" DynamicVerticalOffset="1" StaticEnableDefaultPopOutImage="false"
            Orientation="Horizontal">
            <StaticHoverStyle CssClass="menuBarHover" />
            <DynamicHoverStyle CssClass="menuBarHover" />
            <StaticMenuItemStyle CssClass="menuItem" />
            <DynamicMenuItemStyle CssClass="menuItemDynamic" />
            <DataBindings>
                <asp:MenuItemBinding DataMember="Menu" TextField="text" ValueField="text" NavigateUrlField="url" />
                <asp:MenuItemBinding DataMember="SubMenu" NavigateUrlField="url" TextField="text"
                    ValueField="text" />
            </DataBindings>
        </asp:Menu>



Code to be put in ASPX.CS file (server side code)
string xmlPath = Server.MapPath("~/App_Data/XMLMenu.xml");

        XmlDataSource xmlDS = new XmlDataSource();
        xmlDS.DataFile = xmlPath;
     
        xmlDS.XPath = "Home/Role[@id='" + iRole + "']";

        Menu1.DataSource = xmlDS;
        Menu1.DataBind();
        Menu1.Items[0].Text="";
        Menu1.Items[0].Value="";
        Menu1.Items[0].Selectable=false;
Add XML File Used in this Code 
<?xml version="1.0" encoding="utf-8" ?>
<Home>
    <Role id="1">
        <Menu text="Books" url="MenuFromXml.aspx">
            <SubMenu text="Asp.Net" url="MenuFromXml.aspx"></SubMenu>
            <SubMenu text="Ajax" url="MenuFromXml.aspx"></SubMenu>
            <SubMenu text="MS SQL Server 2005" url="MenuFromXml.aspx"></SubMenu>
            <SubMenu text="JavaScript" url="MenuFromXml.aspx"></SubMenu>
        </Menu>
        <Menu text="Electronics"  url="MenuFromXml.aspx">
            <SubMenu text="Camera" url="MenuFromXml.aspx">
                <SubMenu text="Digital" url="MenuFromXml.aspx">
                    <SubMenu text="Canon" url="MenuFromXml.aspx"></SubMenu>
                    <SubMenu text="Kodak" url="MenuFromXml.aspx"></SubMenu>
                    <SubMenu text="Sony" url="MenuFromXml.aspx"></SubMenu>
                    <SubMenu text="Casio" url="MenuFromXml.aspx"></SubMenu>
                    <SubMenu text="Fuji" url="MenuFromXml.aspx"></SubMenu>
                </SubMenu>
                <SubMenu text="Film Camera" url="MenuFromXml.aspx"></SubMenu>
            </SubMenu>
            <SubMenu text="DVDs" url="MenuFromXml.aspx">
                <SubMenu text="Comedy" url="MenuFromXml.aspx">
                    <SubMenu text="English" url="MenuFromXml.aspx"></SubMenu>
                    <SubMenu text="French" url="MenuFromXml.aspx"></SubMenu>
                    <SubMenu text="German" url="MenuFromXml.aspx"></SubMenu>
                    <SubMenu text="Spanish" url="MenuFromXml.aspx"></SubMenu>
                </SubMenu>
                <SubMenu text="Kids Movies" url="MenuFromXml.aspx"></SubMenu>
                <SubMenu text="Romance Movies" url="MenuFromXml.aspx"></SubMenu>
                <SubMenu text="Action Movies" url="MenuFromXml.aspx"></SubMenu>
            </SubMenu>
        </Menu>
        <Menu text="Contact Us" url="MenuFromXml.aspx"></Menu>
    </Role>
    <Role id="2">
        <Menu text="Books" url="MenuFromXml.aspx">
            <SubMenu text="Asp.Net" url="MenuFromXml.aspx"></SubMenu>
            <SubMenu text="Ajax" url="MenuFromXml.aspx"></SubMenu>
            <SubMenu text="MS SQL Server 2005" url="MenuFromXml.aspx"></SubMenu>
            <SubMenu text="JavaScript" url="MenuFromXml.aspx"></SubMenu>
        </Menu>
        <Menu text="Contact Us" url="MenuFromXml.aspx"></Menu>
    </Role>
</Home>