Sunday 29 December 2013

Life Secure Question .1

1.  How we make our session Cookies less?

What happens if cookies are not supported? ASP.NET server fails to track the session information. Then cookieless sessions are the best option. If you set the cookieless attribute of the sessionState element to "true" in your web.config, you will notice that sessions still work perfectly.
<sessionState cookieless="true" />

2. In which Namespace our assembly loads?

Assembly Class Represents an assembly, which is a reusable, versionable, and self-describing building block of a common language runtime application.



Namespace:  System.Reflection
Assembly:
  mscorlib (in mscorlib.dll)
They are partially compiled code libraries that form the fundamental unit of deployment, versioning, activation scoping, reuse, and security.
An assembly is a set of one or more modules and classes compiled in MSIL, and metadata that describes the assembly itself, as well as the functionalities of the assembly classes.
Name the different components of an assembly.
An assembly is a logical unit that is made up of the following four different types of components:
  • Assembly manifest
  • MSIL source code
  • Type metadata
  • Resources
What are the different types of assemblies? Explain them in detail.
The following are the two types of assemblies:
  • Private Assembly - Refers to the assembly that is used by a single application. Private assemblies are kept in a local folder in which the client application has been installed.
  • Public or Shared Assembly - Refers to the assembly that is allowed to be shared by multiple applications. A shared assembly must reside in Global Assembly Cache (GAC) with a strong name assigned to it.
                                            

3. Do namespace using directives affect assembly loading?
When using directives are declared outside of a namespace, the .Net Framework will load all assemblies referenced by these using statements at the same time that the referencing assembly is loaded.
However, placing the using statements within a namespace element allows the framework to lazy load the referenced assemblies at runtime.
using System;
using System.Collections.Generic;
using System.Text;



namespace MyNameSpace
{
    // ...
}

4. Which command is used to register our assembly in GAC?

There are two ways to install an assembly into the global assembly cache:

You can use Gacutil.exe to add strong-named assemblies to the global assembly cache and to view the contents of the global assembly cache.
            Ex: gacutil -i hello.dll
 
Using Microsoft Windows Installer.
This is the recommended and most common way to add assemblies to the global assembly cache. The installer provides reference counting of assemblies in the global assembly cache, plus other benefits.


5. Difference b/w function and stored procedure?

Procedure can return zero or n values whereas function can return one value which is mandatory.

Procedures can have input/output parameters for it whereas functions can have only input parameters.

Procedure allows select as well as DML statement in it whereas function allows only select statement in it.

Functions can be called from procedure whereas procedures cannot be called from function.

Exception can be handled by try-catch block in a procedure whereas try-catch block cannot be used in a function.

We can go for transaction management in procedure whereas we can't go in function.

Procedures cannot be utilized in a select statement whereas function can be embedded in a select statement.

UDF can be used in the SQL statements anywhere in the WHERE/HAVING/SELECT section where as Stored procedures cannot be.

UDFs that return tables can be treated as another rowset. This can be used             in JOINs with other tables.

Inline UDF's can be thought of as views that take parameters and can be used in JOINs and other Rowset operations.

6. What is static classes?

C# provides the important feature to create static classes, there are two main features of a static class, one is no object of static class can be created and another is, a static class must contain only static members, then it is important that what is the main benefit to create a static class, the main benefit of making static class, we do not need to make any instance of this class ,all members can be accessible with its own name.
Declaration:
A static class is created by using keyword 'Static' as shown here:
Static class Clasname
{
   //C#
}
One more thing that is notable-within static class, all members must be explicitly specified as static, static class does not automatically make its members static. Static class can contain a collection of static methods.
Example:
using System;

static class Shape
{
    public static double GetArea(double Width, double height)
    {
        return Width * Height;
    }
}

class Ractangle
{
    private void GetRactangleArea()
    {
        Double Area;
        Area = Shape.GetArea(10, 5);
    }
}
Shape is static class, it contain static function GetArea. Ractangle is other class and with in GetArea function can be access without creating instance of Class Shape.
Although a static class cannot have an instance constructor, it can have a static constructor.


7. Print todaydate +getdatetime() is it possible?
No

8. What is .Net Remoting?
Establishing communication between objects that run in different processes, whether on the same computer or on computers thousands of miles apart, is a common development goal, especially when building widely-distributed applications. Traditionally, this has required in-depth knowledge not only of the objects on either end of the communication stream, but also of a host of lower-level protocols, application programming interfaces, and configuration tools or files. In short, it was a complex task demanding concentration and experience.
The .NET Framework makes several communication methods available to accomplish this task quickly and easily, even with minimal knowledge of protocols and encodings. As a result, whether you need to develop a Web application quickly or spend more time building a critical enterprise-wide application that involves many computers or operating systems and uses multiple protocols and serialization optimizations, the .NET Framework supports your scenario. Communicating across processes is still a complex task, but much of it is now handled by the .NET Framework.
.NET remoting enables client applications to use objects in other processes on the same computer or on any other computer available on its network. You can also use .NET remoting to communicate with other application domains in the same process. .NET remoting provides an abstract approach to interprocess communication that separates the remotable object from a specific server and client process and from a specific mechanism of communication. As a result, it is flexible and easily customizable. You can replace one communication protocol with another communication protocol, or one serialization format with another without recompiling the client or the server. In addition, the remoting system assumes no particular application model. You can communicate from a Web application, a console application, a Windows Service – from almost anything you want to use. Remoting servers can also be any type of executable application. Any application can host remoting objects and thus provide its services to any client on its computer or network.


9. What is different type of caching in C#?

Caching is a technique of persisting the data in memory for immediate access to requesting program calls. Many in the developer community consider caching as one of the features available to improve performance of Web applications.

Page output caching [Output caching]
Fragment caching [Output caching]
Data caching
and somewhere
There are two different types of caching in ASP.NET:
* Application caching
* Page output caching


10. How you convert a given format of date?

The following script uses the CONVERT() function to display different formats. We will use the GETDATE() function to get the current date/time:
CONVERT(VARCHAR(19),GETDATE())
CONVERT(VARCHAR(10),GETDATE(),10)
CONVERT(VARCHAR(10),GETDATE(),110)
CONVERT(VARCHAR(11),GETDATE(),6)
CONVERT(VARCHAR(11),GETDATE(),106)
CONVERT(VARCHAR(24),GETDATE(),113)









1. How we can add same dll name in one project?

Using extern alias to bring the assemblies in with different namespaces. If you can differenciate the namespace, you should be able to use using altType1 = someProduct.Type1 to create a local alias for the type.
First qualify the assemblies from the command line:
/r:ProductA=companyDLLA.dll
/r:ProductB=companyDLLB.dll
Then reference them using extern alias:
extern alias productA;
extern alias productB;
Finally you can alias the local types:
using productTypeA = productA.Type1;
using productTypeB = productB.Type1;


2. If two server is same and IP address are same but sql sever are different then how can we connect it through IP address?
3. How much web config is possible in our ASP.Net project root directory?

You can have multiple configuration files in your project at the same level too. We do it like this. We have one main configuration file (Web.Config), then we have two more configurations files. App.Config and Database.Config. in App.Config we defined all the application level settings. in Database.Config we define all the database level settings. And in Web.Config we refer App.Config and Database.Config like this:
 <appSettings configSource="app.config">
 </appSettings>
 <connectionStrings configSource="database.config">
 </connectionStrings>
Also , you can have multiple web.config files in sub directories. Settings will be override automatically by asp.net.

4. How we perform that data is not insert our database page is post back through our browser?

We can use ajax. We can use Update panel.. Simple add <asp:Updatepanel...  in your aspx page, and the entire page wont post back.

5. What is Is Post Back property?

This property is used to check whether the page is being loaded and accessed for the first time or whether the page is loaded in response to the client postback. 
Example: 
Consider two combo boxes 
In one lets have a list of countries 
In the other, the states. 
Upon selection of the first, the subsequent one should be populated in accordance. So this requires postback property in combo boxes to be true.

6. Path of the machine config file in our system.

C:\WINDOWS\Microsoft.NET\Framework\<Version>\CONFIG\machine.config
web.config: It 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. The web.config file contains information that control module loading, security configuration, session state configuration, and application language and compilation settings. Web.config files can also contain application specific items such as database connection strings.
 
machine.config: It contains settings that apply to an entire computer. This file is located in the 
%runtime installpath%\Config directory. Machine.config contains configuration settings for machine-wide assembly binding, built-in remoting channels, and ASP.NET.

7. Difference b/w website and web application in asp.net?

Web Application

1. If we create any class files / functions those will be placed anywhere in the applications folder structure and it is precompiled into one single DLL.

2. In web application we have chance of select only one programming language during creation of project either C# or VB.NET.

3. Whenever we create Web Application those will automatically create project files (.csproj or .vbproj).

4. We need to pre-compile the site before deployment.

5. If we want to deploy web application project we need to deploy only .aspx pages there is no need to deploy code behind files because the pre-compiled dll will contains these details.

6. If we make small change in one page we need to re-compile the entire sites.

WebSite

1. If we create any class files/functions those will be placed in ASP.NET folder (App_Code folder) and it's compiled into several DLLs (assemblies) at runtime.

2. In website we can create pages in multi programming languages that means we can create one page code in C# and another page code in vb.net.

3. Web Sites won’t create any .csproj/.vbproj files in project


4. No need to recompile the site before deployment.

5. We need to deploy both .aspx file and code behind file.

6. If we make any code changes those files only will upload there is no need to re-compile entire site  

8. Which datatype is used for an image in database?

Binary data types of either fixed length or variable length.
binary [ ( n ) ]
Fixed-length binary data with a length of n bytes, where n is a value from 1 through 8,000. The storage size is n bytes.
varbinary [ ( n | max) ]
Variable-length binary data. n can be a value from 1 through 8,000. max indicates that the maximum storage size is 2^31-1 bytes. The storage size is the actual length of the data entered + 2 bytes. The data that is entered can be 0 bytes in length. The ANSI SQL synonym for varbinary is binary varying.


9. By default what access modifier in C#?

 Namespace will not have access modifier.
 Default access modifier for class ,struct, Interface, Enum, Delegate  is        Internal.
 Default access modifier for class and struct members is private.
 No access modifier can be applied to interface members and always  interface members are public.
 Enum members are always public and no access modifier can be applied.
 

10. If we delete global.asmx then our site run or not?

n ASP.net site can run without the global.asax file. Here is a question which talks about alternatives of global.asax file.
Even if you delete a global.asax file your site will work.


1. How we add any text file with dll?

Right-click the project file, select Properties.
In the window that opens, go to the Resources tab, and if it has just a blue link in the middle of the tab-page, click it, to create a new resource.
Then from the toolbar above the tab-page, select to add a new text file, give it a name, it will be added to your project and opened up.
If you get this far, then in your code you can type in Resources. TheNameYouGaveTheTextFileHere and you can access its contents. Note that the first time you use the Resources class in a class, you need to add a using directive (hit Ctrl+. after typing Resources to get the menu to get VS to do it for you).

2. Why we use abstract class and interfaces in C#?

Abstract Class: 
An abstract class is a special kind of class that cannot be instantiated. So, why we need a class that cannot be instantiated? An abstract class is only to be inherited from. In other words, it only allows other classes to inherit from it but cannot be instantiated. The advantage is that it enforces certain common behavior or properties across multiple classes who inherit the abstract class. 

Declaration: 
public abstract class Employee 
{ 
public virtual String CalculateSalary() 
{ 
//Can provide default behavior 
} 
} 

An interface is an entity that is defined by the word Interface. An Interface only contains signature of the methods whose implementation is to be provided by the classes who implements that Interface. 

Declaration: 
public interface IEmployee 
{ 
String CalculateSalary(); //Only Signature can be specified not even access modifiers. 
} 

3.  In C# app_code can we take vb.net class?
Add a web.config file to your web site and add the following markup to it:
Web Config Code
Here, we added <compilation> section. The <codeSubDirectories> section defines a set of sub-directories relative to App_Code folder that are compiled at run time. The directoryName attribute points to the sub-folder of App_code. Each sub folder is compiled separately and hence each can have classes coded in different languages. We added our CSCode and VBCode folder in this section. This way the compiler will compile classes from CSCode and VBCode folders separately.
After configuring the web site try to compile it. This time it compiles successfully.

4. Can we use stored procedure in user defined function?

Procedures cannot be called from function.

5. Difference b/w web user control and custom control?

User Controls:- 

1)User controls are custom, reusable controls. 

2)User Control can access only within the current project.if u want to access the user control to 
other application,u have to include that user control to that application.Only after that u able to use it. 

3) User Control can't included in the visual studio IDE. 

4) User Controls are easily created but its very hard. 

Custom Control:- 

1) Custom controls are compiled code components that execute on the server. 

2) Custom control can access from any application because it is stored in the Global Assembly Cache. 

3) Where as Custom Control easily include in the Visual Studio IDE. 

4) On the other hand Custom Control are very hard to create but they are easily used. 

6. What is garbage collection?


The .NET Framework's garbage collector manages the allocation and release of memory for your application. Each time you create a new object, the common language runtime allocates memory for the object from the managed heap. As long as address space is available in the managed heap, the runtime continues to allocate space for new objects. However, memory is not infinite. Eventually the garbage collector must perform a collection in order to free some memory. The garbage collector's optimizing engine determines the best time to perform a collection, based upon the allocations being made. When the garbage collector performs a collection, it checks for objects in the managed heap that are no longer being used by the application and performs the necessary operations to reclaim their memory.

No comments:

Post a Comment