Top 10 Asp.net Web Config Interview Questions

Web config interview questions and answers asp.net


Today, In this tutorial I am going to talk about asp.net web.config file and its uses, we will also talk about the FAQ of web config, which is asked in asp.net interview. As shown by the name "wen.config" it means web configuration. Where we can do custom configuration like URL Rewriting, Authentication and authorization, connection and all. So let's see how it works and the important question which is asked during the interview.

Top 10 Asp.net Ceb Config Interview Questions


Some main work of web.config file

  • Custom error configuration (for 404, 403, other error of application)
  • Database connection configuration.
  • Error handling.
  • Security.
  • Url rewriting.
  • Declaration of variables (key) -- For global use in the application.

Web config interview questions


Q.1) What is a web.config file.
Ans: Web. Config is an application configuration file of asp.net application which is written in XML Format. Every root directory has only one web config file. We can have multiple web config files in our asp.net application there is no restriction to use the web.config file.

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

Q.3) What is the format of the web.config file.
Ans: XML Format.

Q.4) Can the ASP.NET project run without a Web.config file?
Ans: Yes we can run.

Q.5) Can we have multiple web.config in one application
Ans: Yes, we can have multiple web config in one application, but one directory can contain only one web config.

Q.6) How you will configure the connection for the database in web config?
Ans: By adding the <connectionstring> </connectionstring> tag, later on we will configure our connection between these tag.

  <connectionStrings>
    <add name="mydatabasename" connectionString="Data Source=.;Initial Catalog=list4business;Integrated Security=true; timeout=10000;" />
  </connectionStrings>

In the above <connectionStringswe have multiple attributes in <add> tag. let's know about each part on the above connection line.
name is used for the connection name, later with help of this name we can call our connection string.
connectionString is used for the connection with the database (SQL, Oracle). In connectionString we have Data Source, Initial Catalog, Integrated security.

Q.7) Write the syntax of the app setting in the web config.
Ans: In-App setting, we can add values in key-value format and later on we can use it multiple times according to our requirement.

<configuration>        
    <appSettings>
      <add key="registration_email_id" value="[email protected]" />
    </appSettings>

</configuration>

How to use appsetting in cs page of application.

string email_id = ConfigurationSettings.AppSettings["registration_email_id"];

Q.8) Can we set the startup page on the web.config file.
Ans: We can set a startup page on web config by using some code. First, find the System.webserver in web config and write the following code within <system.webServer</system.webServer>
Tag.

<system.webServer>
<defaultDocument enabled="true">
 <files>
    <clear/>
    <add value="index.aspx"/>
 </files>
</defaultDocument>
<system.webServer>

In the Above source code index.aspx will be your startup page.

Q.9) How to Use Web. Config customErrors for ASP.NET.
Ans: In asp.net application customErrors support mainly 3 types of modes.
1.On
2.Off
3.RemoteOnly


Q.10: How to increase request time out by web config.
Ans: By adding the following code in web config under the<system.web</system.web> 
<system.web>
    <httpRuntime executionTimeout="180" />
</system.web>
Q.11 How to  Enable SSL in the web.config asp.net
Ans: By the following code.

<system.webServer>
        <rewrite>
            <rules>
                <clear />
                <rule name="Redirect to https" stopProcessing="true">
                    <match url=".*" />
                    <conditions>
                        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
                    </conditions>
                    <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
                </rule>
            </rules>
        </rewrite>

    </system.webServer>




I hope you like this "Web config interview questions". Please don't forget to comment below. If you found it to be helpful.

2 Comments

  1. can we modify web.config file in run time?
    please tell me

    ReplyDelete
  2. Hi shekher, It is not good practice to modify web config at run, if you do some changes active user on website will get error....

    ReplyDelete

Post a Comment

Post a Comment

Previous Post Next Post