Friday, December 31, 2010

Difference Between Server.Transfer and Response.Redirect

Server.Transfer and Response.Redirect are used to transfer the control from one page to other. But there are some differences in both which are listed below.

Response.Redirect(..) :- Response.Redirect sends HTTP code 302 down to the users browser along with the new URL location of the wanted page.HTTP Code 302 actually means ' The requested resource resides temporarily under a different URI'.
After browser receives this code it send a request to server for that resource or page.
This actually causes two requests to the server, first one to the original URL, and second to the new URL that is suggested via 302 response.

Server.Transfer(..) :- In contrast to all this when we call Server.Transfer we do not initiate another request to the server, but the original request is simply rewritten and transferred to some other page on the same server.
(This off course means that we can use it only to transfer requests to the pages on the same server, not to some other servers and we can only transfer to .aspx pages and not other page types like HTML, php etc).

When Repsponse.Redirect("Temp.aspx") line execute server say to client browser to send a request for Temp.aspx. Than Client browser request for Temp.aspx.While in case of Server.Transfer("Temp.aspx") Server does not say anything to client browser just send Temp.aspx page.

1) In Response.Redirect previous page is not accessible while in Server.Transfer it is optional.
Server.Transfer(URL,bPreserveForm);

2) Server.Transfer use only within the server.But Response.Redirect can be use ouside the server.But it should be a full path like http://www.google.com only www.google.com will not work

3)Resonse.Redirect can be used both for aspx and html or php pages.But Server.Transfer is only used for .aspx pages it will not work for html pages.

4) Response.Redirect use only get method to post variables form one page to another means we need to give in query string if we want to pass some variables to next page. But in case of Response.Transfer you can use post method with the help of Context.Item[“Message”].

5)In Response.Redirect you see the full url with values in browser and in Server.Transfer you can not see it.

6)Secondly, Server.Transfer maintains the original URL in the browser. This can really help streamline data entry techniques, although it may make for confusion when debugging.

8)In case of Server.Transfer you can use Context.Items["Message"] to store and get the values but in case of Response.Redirect you can not save values with this method.

9)One thing to be careful about when using the Server.Transfer is to clear the HttpResponse object with Response.Clear method on the transferred page to avoid any output from the first page to be shown on the second page.

10)In Server.Transfer url remain same there Bookmark can not be used while in case of Response .Redirect Bookmark can be use.

Server Transfer

1. Client Request Page HelloWorld.ASPX
2. Server.Transfer -> Server send a different page to the client
3. Client Receives Page still thinking it's HelloWorld.ASPX.
4. Client's URL (Address bar) remains HelloWorld.ASPX since the page was
sent on the server side and the client doesn't know a different page was
sent.

Response.Redirect

1. Client Requests Page HelloWorld.ASPX
2. Response.Redirect -> Server sends a HTTP header informing that the
user should redirect.
3. Client sees the redirect notice and requests
AnotherPage.ASPX
4. Server sends AnotherPage.ASPX
5. Client's URL (address bar) shows AnotherPage.ASPX

Don't confuse Server.Transfer with Server.Execute, which executes the page and returns the results. It was useful in the past, but, with ASP.NET, it's been replaced with fresher methods of development. Ignore it.

Friday, December 24, 2010

Interview Questions - 4

Questions Shared by Arvind Kumar Rathour
Coalesce function return not null value. It is more power full than ISNULL. ISNULL takes two parameters while coalesce can take n number of parameters. This function returns left most non null value. If all arguments are null than coalesce returns null. You can not pass single parameter in coalesce., this will give compile time error


SELECT COALESCE(NULL, NULL, 'foo',NULL,NULL,NULL)

Output : foo

SELECT ISNULL(NULL, 'foo')

Output : foo

SELECT ISNULL(NULL, 'foo',’fop’)

Error : The isnull function requires 2 argument(s).





ASP .Net
- Difference between asp and asp.net
- How do you do exception management?
- If you are using components in your application, how can you handle exceptions raised in a component?
- Can we throw exception from catch block?
- How do you relate an .aspx page with its code behind page?
- What are the types of assemblies and where can u store them and how?
- What is difference between value and reference types?
- Is array reference type / value type?
- Is string reference type / value type?
- What is web.config. How many web.config files can be allowed to use in an application?
- What is difference between machine.config and web.config?
- What is shared and private assembly?
- What are asynchronous callbacks?
- How to write unmanaged code and how to identify whether the code is managed / unmanaged?
- How to authenticate users using web.config?
- What is strong name and which tool is used for this?
- What is gacutil.exe. Where do we store assemblies?
- Should sn.exe be used before gacutil.exe?
- What does assemblyinfo.cs file consists of?
- What is boxing and unboxing?
- Types of authentications in ASP.NET?
- Difference between Trace and Debug?
- Difference between Dataset and DataReader.
- What is custom tag in web.config?
- How do you define authentication in web.Config?
- What is sequence of code in retrieving data from database?
- About DTS package.
- What provider ADO.net use by default?
- Where does web.config info stored? Will this be stored in the registry?
- How do you register the dotnet component or assembly?
- What is stateless asp or asp.net?
- Authentication mechanism in dotnet
- State management in asp.net
- Types of values mode can hold session state in web.config
- About WebService
- What are Http handler?
- What is view state and how this can be done and was this there in asp?
- Types of optimization and name a few and how do u do?
- About DataAdapters
- Features of a Dataset
- How do you do role based security?
- Difference between Response.Expires and Expires.Absolute?
- Types of object in asp.
- About duration in caching technique.
- Types of configuration files and the differences.
- Difference between ADO and ADO.net.
- About Postback.
- If you are calling three SPs from a window application how do u check for the performance of the SPS?


#61607;Database

- What is normalization?
- What is an index and types of indexes. How many number of indexes can be used per table?
- What is a constraint. Types of constraints?
- What are code pages?
- What is referential integrity?
- What is a trigger?
- What are different types of joins?
- What is a self join?
- Authentication mechanisms in Sql Server.
- What are user defined stored procedures?
- What is INSTEAD OF trigger?
- Difference between SQL server 7.0 and 2000?
- How to optimize a query that retrieves data by joining 4 tables?
- Usage of DTS.
- How to disable an index using select query?
- Is non-clustered index faster than clustered index?
- Types of optimization in queries?
- Difference between ISQL and OSQL?
- How you log an exception directly into sql server what is used for this?
- About Replication in Database.
- What is the default optimization done in oracle and sql server?
- How can i make a column as unique?
- How many no of tables can be joined in same sql server?
- How many column can exist per table?
- About Sql Profiler usage?


• Technical

#61607; .NET-
- How do you handle session management in ASP.NET and how do you implement them. How do you handle in case of SQLServer mode.
- What are different authentication types. How do you retrieve user id in case of windows authentication
- For a server control, you need to have same properties like color maxlength, size, and allowed character throughout the application. How do you handle this.
- What is custom control. What is the difference between custom control and user control
- What is the syntax for datagrid and specifying columns
- How do you add a javascript function for a link button in a datagrid.
- Does C# supports multi-dimensional arrays
- How to transpose rows into columns and columns into rows in a multi-dimensional array
- What are object oriented concepts
- How do you create multiple inheritance in C#
-- Features and disadvantages of dataset
- What is the difference between and ActiveX dll and control
- How do you perform validations
- What is reflection and disadvantages of reflection
- What is boxing and how it is done internally
- Types of authentications in IIS
- What are the security issues if we send a query from the application
- Difference between ByVal and ByRef
- Disadvantages of COM components

- How do we invoke queries from the application
- What is the provider and namespaces being used to access oracle database
- How do you load XML document and perform validation of the document
- How do you access elements in XML document
- What is ODP.NET
- Types of session management in ASP.NET
- Difference between data reader and dataset
- What are the steps in connecting to database
- How do you register a .NET assembly
- Usage of web.config
- About remoting and web services. Difference between them
- Caching techniques in .NET
- About CLS and CTS
- Is overloading possible in web services
- Difference between .NET and previous version
- Types of caching. How to implement caching?
- Features in ASP.NET.
- How do you do validations. Whether client-side or server-side validations are better?
- How do you implement multiple inheritance in .NET?
- Difference between multi-level and multiple inheritance?
- What are runtime hosts?
- What is an application domain?
- What is viewstate?
- About CLR, reflection and assemblies?
- Difference between .NET components and COM components?
- What does assemblyinfo.cs consists?
- Types of objects in ASP?

Thanks Arvind.

Friday, December 17, 2010

Interview Questions-3

1) If you have two text boxes one is multi line and other is single line and both have MaxLength 10. What will be the difference in behavior of both?

In multi line text box Max Length property has been ignored. The reason is that multi line text box converted into textarea and text area does not support max length property.While in single line it consider max length and you can not type more than 10 characters in that. If any how you want to implement MaxLength in multi line text box you can use Validator control or java script validation for that.

2) Can we define Optional Parameter in Stored Procedure in SQL Server?
Yes, We can define optional parameter in a stored procedure following way.

CREATE Procedure sp_User
(
@Name as varchar(20),
@Age int = null
)
AS
INSERT INTO table1
SELECT FROM table2
WHERE table1.Name= @Name
and (@Age is null or Age= @Age)

3) What is equivalent of Variant in VB .Net?
There is no "Variant" type in VB.NET. The closest you can get to that is type Object,which is the Mother Type from which all types descend.

If you define

Dim Var

than Var will work as a Variant also.

If you are calling a Com method which take 5 parameters 3 of them are optional. In VB .Net you can pass only three parameters but in C# it will give compile time error method not found with that signature. In C# you can use

object objVal = Type.Missing.

4) What is .Xap file ?
.xap file is the compressed output file for the Silverlight application. The .xap file includes AppManifest.xaml, compiled output assembly of the Silverlight project (.dll) and any other resource files referred by the Silverlight application.

Web pages like .aspx files and .html files use the Silverlight components by loading the .xap files using the <object> tag in the HTML or by using <asp:Silverlight> tag in the ASP.NET pages.

".xap" files (pronounced "zap") use the standard .zip compression algorithm to minimize client download size. A "hello world" .NET Silverlight application (built using VB or C#) is about 5KB in size.

5) How we define constructor and destructor in VB.Net?
In VB .Net we have Finalize method in place of destructor in C#. we can define it like :-

Protected Overrides Sub Finalize()
Try
Finally
MyBase.Finalize() 'define the destructor
End Try
End Sub

And constructor can be define like :-

Public Sub New() ' define the constructor
End Sub

6) What is the Role of Set NoCount in SQL Server?
When SET NOCOUNT is ON, the count (indicating the number of rows affected by a Transact-SQL statement) is not returned. When SET NOCOUNT is OFF, the count is returned.

Actually when you fire any sql query it returns two things actual result and number of rows affected. Suppuse you have fired a select query. This query returns the rows as a result and in message part it will return number of rows return. It is an extra overhead we can suppress the second message with the use of NoCount.

7) Can we define our global variables in SQL Server?
SQL Server provides a wide range of global variable. But you can not define your own global variables in SQL Server.Some global variables are..

* @@ERROR
* @@IDENTITY
* @@MAXCHARLEN
* @@ROWCOUNT
* @@SERVERNAME
* @@SPID
8) What is Referential Integrity?
Referential integrity is a database concept that ensures that relationships between tables remain consistent. When one table has a foreign key to another table, the concept of referential integrity states that you may not add a record to the table that contains the foreign key unless there is a corresponding record in the linked table. It also includes the techniques known as cascading update and cascading delete, which ensure that changes made to the linked table are reflected in the primary table.

Friday, December 10, 2010

Why property is a better choice instead of public variables?

Property Vs. Public Variable
Properties are better than public variables There are two reasons.

1) Public variables are unsafe, as anyone can set any value and you have no control over them.While in case of property you can put a check that no one could set invalid value to them.

Suppose you have a property Salary..

private int m_iSalary=100;

property int Salary
{
get
{
return m_iSalary;
}

set
{
if(value > 0)
{
m_iSalary=value;
}
else
{
MessageBox.Show("You can not set Negative value in Salary.");
}
}
}

2) We can restrict any one, that he can only get the value but could not set from outside of class and vise versa.

property int Salary
{
get
{
return m_iSalary;
}

private set
{
if(value > 0)
{
m_iSalary=value;
}
else
{
MessageBox.Show("You can not set negative value in Salary.");
}
}
}

But inner access modifier should be more restrictive than main access modifier. We can not define access specifier for both(get and set) in one property, You can set only one at a time. And other will use main access specifier.

In set method value is a keyword you can not use any hard code value or any other variable instead of value keyword.

Monday, December 6, 2010

Use two tables in update statement

You can use more than one table in single update query but you can not update more than one table in single update query in Sql Server.

You have two tables on the base of them you want to fire update statement. Than you can do it like :-

Update Table1 set Field1 ='Name' from Table2 where Table1.ID=Table2.ID

Even you can use more than two tables in a single update query like..

Update Table1 set Field1 ='Name' from Table2,Table3 where Table1.id=Table2.id and Table1.Id= Table3.Id

But you can not update two tables in one query in SQL Server.

In MYSQL it is possible to update two tables in Single Query..

update schoolsdata t1, schoolblog t2 set t1.state='A', t2.studentcomments='Z' where t1.collegeid = t2.collegeid and t1.collegeid=40

Saturday, December 4, 2010

IE8 compatibility Issue

If you have developed a website that is compatible with IE-7 or IE-6. And its designing is not good enough with IE-8 than you can force IE-8 to use IE-7 or IE-6 rendering mode until you fix the issue with IE-8.

This can be done with the help of meta tag :

<head>
<meta http-equiv="X-UA-Compatible" content="IE=7"/>
</head>




you can change here content attribute's value according to your requirement(IE-8,IE-7,IE-6,IE-5).

On the other hand if you have developed a windows application and used web browser control. Web Browser control by default gives IE-6 views for XP. But you want, it should use IE-8 rendering mode than also you can use above meta tag with the xslt you are using.

If don't want to change xslt than you can do the setting in registry also like:-

For IE-8 rendering mode
[(HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE)\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION]
"ApplicationName.exe" = dword 8000 (Hex: 0x1F40)

and For IE-7 you can use "ApplicationName.exe" = dword 7000 (Hex: 0x1B58)

Or you can save following code as IE8.reg file(Simple create a notepad file and paste following code in that). And when you will double click on that file it will do the setting automatically. Following code is for IE-8 only.

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION]
"ApplicationName.exe"=dword:00411f40

Thursday, December 2, 2010

RPC Sever not available

Sometimes you get this error -> Error : RPC Sever not available. What is it mean?

What is RPC?Microsoft Remote Procedure Call is an inter process communication mechanism that enables two processes to communicate and exchange data. Processes may be on the same computer or on LAN or across the internet.


There is a service named RPC that should be always running on host computer to use RPC. Sometimes it stopped due to some malfunction, due to some anti virus or due to to some spy ware or by any other reason.

You can check it whether it is running or not.
Go to Control Panel/Administrative Tools/Services then double click on the Remote Procedure Call entry and either start the server, or set it to start automatically on system start up.

If it is not there you have to check registry entry for this service. If it is not present in registry than you will not find it in services.You can add it in registry.By exporting it from another system on which it is working fine.

Registry Path :- HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\RpcSs

If you don't another PC to export the correct registry file you can save following code as .reg file and when will double click on that file it will automatically import.

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\RpcSs]
"Description"="Provides the endpoint mapper and other miscellaneous RPC services."
"DisplayName"="Remote Procedure Call (RPC)"
"ErrorControl"=dword:00000001
"Group"="COM Infrastructure"
"ImagePath"=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,\
74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,73,\
00,76,00,63,00,68,00,6f,00,73,00,74,00,20,00,2d,00,6b,00,20,00,72,00,70,00,\
63,00,73,00,73,00,00,00
"ObjectName"="NT Authority\\NetworkService"
"Start"=dword:00000002
"Type"=dword:00000010
"FailureActions"=hex:00,00,00,00,00,00,00,00,00,00,00,00,01,00,00,00,00,00,00,\
00,02,00,00,00,60,ea,00,00
"ServiceSidType"=dword:00000001

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\RpcSs\Parameters]
"ServiceDll"=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,\
00,74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,\
72,00,70,00,63,00,73,00,73,00,2e,00,64,00,6c,00,6c,00,00,00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\RpcSs\Security]
"Security"=hex:01,00,14,80,a8,00,00,00,b4,00,00,00,14,00,00,00,30,00,00,00,02,\
00,1c,00,01,00,00,00,02,80,14,00,ff,01,0f,00,01,01,00,00,00,00,00,01,00,00,\
00,00,02,00,78,00,05,00,00,00,00,00,14,00,8d,00,02,00,01,01,00,00,00,00,00,\
05,0b,00,00,00,00,00,18,00,ff,01,0f,00,01,02,00,00,00,00,00,05,20,00,00,00,\
20,02,00,00,00,00,18,00,8d,00,02,00,01,02,00,00,00,00,00,05,20,00,00,00,23,\
02,00,00,00,00,14,00,9d,00,00,00,01,01,00,00,00,00,00,05,04,00,00,00,00,00,\
18,00,9d,00,00,00,01,02,00,00,00,00,00,05,20,00,00,00,21,02,00,00,01,01,00,\
00,00,00,00,05,12,00,00,00,01,01,00,00,00,00,00,05,12,00,00,00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\RpcSs\Enum]
"0"="Root\\LEGACY_RPCSS\\0000"
"Count"=dword:00000001
"NextInstance"=dword:00000001

Wednesday, December 1, 2010

Finally Block

How to work with finally?
Finally block guarantees to execute in each and every condition whether it is successful completion of a function or any error has been occurred not matter finally block would execute definitely.But control should come in try block if it did not come in try block and return before try block than finally will not execute.

Example 1

private void Show()
{
try
{
Console.Writeline("In try");
return;
}
catch(Exception ex)
{
throw ex;
}

finally
{
Console.Writeline("Finally");
}
}

Output :- In try Finally
Example 2

private void Show()
{
Console.Writeline("In Function");
try
{
Console.Writeline("In try");
return;
}

catch(Exception ex)
{
throw ex;
}

finally
{
Console.Writeline("Finally");
}
}

Output :- In Function In try Finally

Finally block used for to close any open file or connection or to null the reference type variables or for all type of work that you want to do in each and every condition.

There is some limitation of finally block you can not write return statement there since there is a chance that it may override the actual return statement.

If you write return statement there it will throw a compile time error.

"Control cannot leave the body of a finally clause."

Even you can not modify the return value inside finally block. Though it will not give any error but will not affect output.Since return value already decided before it goes to finally block,

public class ReturnExample
{
private String normalExecution()
{
String result = "";
try
{
result = "Entered try block.";
return result;
}

catch(Exception e)
{
result = result + "Entered Catch block.";
return result;
}

finally
{
result = result + "Entered finally block.";
}
}

public static void main(String[] args)
{
ReturnExample example = new ReturnExample();
String result = example.normalExecution();
Console.Writeline(result);
}

Output :- Entered Try block.


Finally block is not like if or for means in case of if or for there is no need of braces if we have only one line but same is not true for finally. Braces are compulsory for finally.Although you can write only try and catch or try and finally.

These are all correct
try
{
}
catch
{
}

or
try
{
}
finally
{
}

Followers

Link