ASP.NET Interview Questions and Answers (1544) - Page 75

How many types of Session-State Modes are there in Asp.Net?

NOTE: This is objective type question, Please click question title for correct answer.
How can we provide User Friendly 404 Pages if we do not find page?

Instead of showing File Not Found error message we can handle this error with code in global.asax file. We need to write code in Application_Error event as:-

void Application_Error(object sender,EventArgs e) 

{
//Code that runs when an unhandled error occurs
Exception Ex = Server.GetLastError().GetBaseException();
if (ex.GetType() == typeof(System.IO.FileNotFoundException))
{
Response.Redirect("Default404.aspx");
}
}

What is the use of Session.IsNewSession property in Asp.Net?

Session.IsNewSession property lets us know if Session is created during current request or not.If value is true,then it is a new Session.If value is false,then it is existing active Session created before.
How to check Check Whether IIS is Running or Not?

We can check whether IIS manager is running or not using ServiceController class as:-

using System;

using System.ServiceProcess;

ServiceController sc = new ServiceController("W3SVC");
Response.Write(sc.Status.ToString());

How to Redirect user to another page after Session gets Over or End?

In Web.Config file,we can do:-
<authentication mode="Forms">

<forms loginUrl = "~/Login.aspx" slidingExpiration = "true" timeout = "20" />
</authentication>

Here,20 is a Timeout in MINUTES.
Response.Redirect method returns which status code?

NOTE: This is objective type question, Please click question title for correct answer.
How to Redirect Page permanently with status code 301 in Dot Net below 4.0 Framework?

Use below code:-
Response.Status = "301 Moved Permanently";

Response.AddHeader("Location", "/new_page.aspx/");
Response.End();

How to Redirect Page permanently with status code 301 in Dot Net 4.0 Framework?

We have Response RedirectPermanent method,hich is introduced in Dot Net 4.0 Framework:-

Response.RedirectPermanent("new_page.aspx",true);

How to get IIS Version using Asp.Net?

To find out which version of IIS hosts our web application,we can use SERVER_SOFTWARE from Request.ServerVariables collection as:-

Response.Write(Request.ServerVariables["SERVER_SOFTWARE"]);

What do we mean by an HTTP Module?

Simply an HTTP module is a piece of code that sits between the client and the web server.All the request that are made through the Web Server passes through HTTP Module.So,we can say that an HTTP Module is an mediator between Client and the Web Server.
How to Get Server Computer Name in Asp.Net?

To get computer name of our Web Server with Asp.Net Server Side code,first we need to add a reference to System.Windows.Forms Namespace and then use code like this:-
using System.Windows.Forms;


protected void Page_Load(object sender, EventArgs e)
{
string Server_Name = String.Empty;
Server_Name = SystemInformation.ComputerName;
}

How To get Referrer URL in Asp.Net?

Using Request.UrlReferrer,we can get the Referrer URL in Asp.Net as:-
string url = Request.UrlReferrer.ToString();

How to get the previous page URL?

Use Request.UrlReferrer property:-
string previous_page_url = Request.UrlReferrer.ToString();

How To Close Browser Window With Button Click?

Write below code in Page Load Event as:-
btnClose.Attributes.Add("OnClick","window.close();");

How To Get Current URL?

Write below code as:-
string CurrentURL = Request.Url.AbsoluteUri;

How To Get List Of Folders in Asp.Net?

To get a list of all sub directories from one location,we can use GetDirectories method.

string[] Directories = 

System.IO.Directory.GetDirectories(Server.MapPath("~/"));


Server.MapPath("~/") will simply return root folder of web application.
How many ways,we can access the HTML Select DropDownList selected value in Asp.Net code behind?

NOTE: This is objective type question, Please click question title for correct answer.
Which statements is(are) correct about UseSubmitBehavior property of button control in Asp.Net?

NOTE: This is objective type question, Please click question title for correct answer.
What are the various modes of storing Asp.Net Session?

NOTE: This is objective type question, Please click question title for correct answer.
Which one of the following is the last stage of the Web forms life-cycle?

NOTE: This is objective type question, Please click question title for correct answer.
Found this useful, bookmark this page to the blog or social networking websites. Page copy protected against web site content infringement by Copyscape

 Interview Questions and Answers Categories