Blog Home  Home Feed your aggregator (RSS 2.0)  
Software Code Help blogs - C#
newtelligence powered
 
 Thursday, November 06, 2008

1. In the assembly that implements the type(Console), look up the method being called in the metadata.
2. From the metadata, get the IL from this method and verify it.
3. Allocate a block of memory.
4. Compile the IL into native CPU instructions: the native code is saved in the memory allocated in step#3.
5. Modify the method's entry in the Type's table so that it now points to the memory block allocated in Step#3.
6. Jump to the native code contained inside the memory block.

Thursday, November 06, 2008 5:25:33 AM (GMT Standard Time, UTC+00:00)  #    Comments [0]   C#  | 
 Friday, August 01, 2008

Use

Server.UrlEncode

Friday, August 01, 2008 1:50:01 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]   C# | Interview Question ASP.NET  | 
 Monday, June 30, 2008

A Simple Factory pattern is one that returns an instance of one of several possible classes, depending on the data provided to it. Usually all of the classes it returns have a common parent class and common methods, but each of them performs a task differently and is optimized for different kinds of data.

 

 

public abstract class Travel

{

    public abstract decimal GetPrice();

 

    public enum Types

    {

        Air, Hotel, Car

    }

    /// <summary>

    /// This class return value using factory

    /// </summary>

    /// <param name="t"></param>

    /// <returns></returns>

    public static Travel TravelFactory(Types t)

    {

        switch (t)

        {

            case Types.Air:

                return new Air();

 

            case Types.Hotel:

                return new Hotel();

 

            case Types.Car:

                return new Car();

 

        }

 

        throw new System.NotSupportedException("The Travel type " + t.ToString() + " is not recognized.");

    }

}

public class Air : Travel

{

    private decimal m_Price = 23.5M;

    public override decimal GetPrice() { return m_Price; }

}

 

public class Hotel : Travel

{

    private decimal m_Price = 11.5M;

    public override decimal GetPrice() { return m_Price; }

}

 

public class Car : Travel

{

    private decimal m_Price = 16.5M;

    public override decimal GetPrice() { return m_Price; }

}

 

// you can use factory using this code

...

Console.WriteLine( Travel.TravelFactory(Travel.Types.Air).GetPrice().ToString() );

...

Monday, June 30, 2008 5:29:52 AM (GMT Standard Time, UTC+00:00)  #    Comments [0]   C#  | 
 Thursday, June 26, 2008

The ASP.NET configuration section schema contains elements that control how ASP.NET Web applications behave. Our default configuration of web application is set in the Machine.config file that are located in this path c:\Windows\Microsoft.NET\Framework\versionNumber\CONFIG\Machine.config. The setting inside the machine.config file is applied to all web application installed on this System. If you want to change configuration setting for your particular application, Then we create web.config file inside our web application.

Here we specifies the root element for the ASP.NET configuration section. Contains configuration elements that configure ASP.NET Web applications and control how the applications behave.

<system.web>
   <authentication>
   <authorization>
   <browserCaps>
   <clientTarget>
   <compilation>
   <customErrors>
   <globalization>
   <httpHandlers>
   <httpModules>
   <httpRuntime>
   <identity>
   <machineKey>
   <pages>
   <processModel>
   <securityPolicy>      <serviceDescriptionFormatExtensionTypes>    <sessionState>
   <trace>
   <trust>
   <webServices>
 </system.web>

 
Authentication:- For setting our web application authentication inside <Authentication> tag. There are four different type of authentication “None”, “Windows”, “Forms”, “Passport”.
If you do not require any authentication, then use “None” inside mode
.
       <authentication mode="None"/>
Basically we are using Windows authentication as a default authentication. This authentication is handled by Internet Information Server(IIS). This provider uses IIS to perform the authentication and then passes the authenticated identity to your code.
       <authentication mode="Windows"/>

IIS gives you a choice for four different authentication methods: Anonymous, basic, digest, and windows integrated

Internet Information Server(IIS)

If user select anonymous authentication, IIS doesn’t perform any authentication on that web application.

If user select basic authentication, users must provide a windows username and password to connect. How ever this information is sent over the network in clear text, which makes basic authentication very much insecure over the internet.

If user select digest authentication, users must still provide a windows user name and password to connect. This information requires that all users be running Internet Explorer 5 or later and that windows account to stored in active directory.

If you select windows integrated authentication, passwords never cross the network. Users must still have a username and password, but the application uses either the Kerberos or challenge/response protocols authenticate the user.

Forms authentication uses web application forms to collect the user credential and on the basis of his credential, it takes action on web application

    <authentication mode="Form">
         <Form name="Form" LoginUrl = “index.aspx”>
    </authentication>
Passport authentication is provided by the Microsoft. RedirectUrl specifies the page to redirect to if the page requires authentication and the user has not signed on with passport.
    <authentication mode="Passport">
        <passport redirectUrl="internal"/>
    </authentication>

Passport authentication uses an encryption mechanism to indicate that login user is valid user or not. If user successfully login then it is a valid user otherwise is will be redirected back to your site mentioned in redirectUrl attribute tag.

For using Passport authentication, you first install Passport Software Development Kit (SDK) on your server. The SDK can be found at http://msdn.microdoft.com/library/default.asp?url=/downloads/list/websrvpass.aps.It includes full details of implementing passport authentication in your own applications.

Authorization:- The <authorization> tag controls client access to web pages resources. This element can be declared at any level (machine, site, application, subdirectory, or page).

 
<authorization>
<
allow users="comma-separated list of users"
roles="comma-separated list of roles"
verbs="comma-separated list of verbs"/>
<
deny users="comma-separated list of users"
roles="comma-separated list of roles"
verbs="comma-separated list of verbs"/>
</
authorization>

<Allow> tag access to a resource based on the following:
users attribute: A comma-separated list of user names that are granted access to the resource. A question mark (?) allows anonymous users; an asterisk (*) allows all users.
roles attribute: A comma-separated list of roles that are granted access to the resource.
verbs attribute: A comma-separated list of HTTP transmission methods that are granted access to the resource. Verbs registered to ASP.NET are GET, HEAD, POST, and DEBUG.

<Deny> tag access to a resource based on the following:
users: A comma-separated list of user names that are denied access to the resource. A question mark (?) indicates that anonymous users are denied access; an asterisk (*) indicates that all users are denied access.
roles: A comma-separated list of roles that are denied access to the resource.
verbs: A comma-separated list of HTTP transmission methods that are denied access to the resource. Verbs registered to ASP.NET are GET, HEAD, POST, and DEBUG.

CustomErrors:- This tag contain the information about the custom error setting. In case any error is coming to your web application then it is redirected to defaultRedirect Url. For enabling and disabling custom error, we specify value inside mode attribute.


<
customErrors defaultRedirect="url" mode="On|Off|RemoteOnly">
<
error statusCode="statuscode" redirect="url"/>
</
customErrors>

“On” indicate then custom error setting is on. In case of error, it will redirected to default url.
“Off” specify that custom error is disable.
“RemoteOnly” specifies that custom errors are shown only to remote clients

Compilation:- Set compilation debug="true" to enable ASPX debugging. Otherwise, setting this value to false will improve runtime performance of this application. Set compilation debug="true" to insert debugging symbols (.pdb information) into the compiled page. Because this creates a larger file that executes more slowly, you should set this value to true only when debugging and to false at all other times. For more information, refer to the documentation about debugging ASP.NET files.

<compilation defaultLanguage="c#" debug="true" />

Trace:- It is used for tracing of execution of your web application. There are two level of tracing, individual page level and application Application-level tracing enables trace log output for every page within an application. Set trace enabled="true" to enable application trace logging. If pageOutput="true", the trace information will be displayed at the bottom of each page. Otherwise, you can view the
application trace log by browsing the "trace.axd" page from your web application root.

For setting for application level trace, we put this code inside web.config file.

<trace
enabled="false"
requestLimit="10"
pageOutput="false"
traceMode="SortByTime"
localOnly="true"
/>

And for page level tracing, we put trace=”true” inside aspx page.

<%@ Page="" language="c#" Codebehind="EmployDetails.aspx.cs" AutoEventWireup="false" Inherits="Salary.Employ" Trace="True" %>

Identity:- This tag control the identity of web application. Impersonation is disabled by default. When using impersonation, ASP.NET applications can optionally execute with the identity of the client on whose behalf they are operating

<identity impersonate="true|false" userName="domain\username" password="password"/>
You can programmatically read the identity of the impersonated user, as shown in the following example.
[Visual Basic]
Dim username As String = System.Security.Principal.WindowsIdentity.GetCurrent().Name
[C#]
String username = System.Security.Principal.WindowsIdentity.GetCurrent().Name;

SessionState:- SessionState is used for specify which option you choose for storing the session for your web application. There are four mode option regarding session state.

“Off” Indicates that session state is not enabled.
“InProc” Indicates that session state is stored locally. Web application in this mode run faster as compared to other session state mode. But problem is that if IIS restart then loss of session data take place.
“StateServer” Indicates that session state is stored on a remote server.
“SQLServer” Indicates that session state is stored on the SQL Server. For this you first run the InstallSQLState.sql script on the SQL Server. The advantage of SQL Server session state is that we can share session state among the different processors in the web garden or Web farm. And disadvantage is slow as compared to InProc mode.
“Cookieless = true” specifies that session is without cookieless should used. And false is the reverse of that.
“Timeout” specifies that session is activated for how much time, if not hit is coming within that time periods then session is expired.
“stateConnectionString” require when you specify mode = StateServer.
“sqlConnectionString” attribute store the connection string of database. And we specify mode = SQLServer.
“stateNetworkTimeout” attribute using StateServer mode to store session state, specifies the number of seconds the TCP/IP network connection between the Web server and the state server can be idle before the session is abandoned. The default is 10.


<
sessionState mode="Off|InProc|StateServer|SQLServer"
cookieless="true|false"
timeout="number of minutes"
stateConnectionString="tcpip=server:port"
sqlConnectionString="sql connection string"
stateNetworkTimeout="number of seconds"/>

Globilization:- This section sets the globalization settings of the application.

<globalization  requestEncoding="utf-8" responseEncoding="utf-8"/>

appSettings:- The <appSettings> element stores custom application configuration information such as database connection strings, file paths, XML Web service URLs, or any information stored in an application's .ini file. The key/value pairs specified in the <appSettings> element can be accessed in code using the System.Configuration.ConfigurationSettings class.

<appSettings>
<
add key="EmailFrom" value="rajshekhar@gmail.com" />
<
add key="cssFile" value="CSS/text.css"/>
<
add key="jsFilePath" value="JavaScript/MenuFunctions.js"/>
</
appSettings>

For accessing the value of appSettings is
strEmail = System.Configuration.ConfigurationSettings.AppSettings[“EmailFrom”];

Thursday, June 26, 2008 12:00:45 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]   C#  | 

In the absence of WCF, this team would need to choose the right distributed technology from the multiple choices offered by the .NET Framework. Yet given the diverse requirements of this application, no single technology would fit the bill. Instead, the application would probably use multiple existing .NET technologies. For example:

·         ASMX, also called ASP.NET Web Services, would be an option for communicating with the J2EE-based existing reservation application and with the partner applications across the Internet. Given that basic Web services are supported today on most platforms, this would likely be the most direct way to achieve cross-vendor interoperability.

·         .NET Remoting is a natural choice for communication with the call center application, since both are built on the .NET Framework. Remoting is designed expressly for .NET-to-.NET communication, so it would offer the best performance for this situation.

·         Enterprise Services (the successor to COM+) might be used by the rental car reservation application for things such as managing object lifetimes and defining distributed transactions. These functions could be useful in communicating with any of the other applications in this scenario, but Enterprise Services supports only a limited set of communication protocols.

 

·         Web Services Enhancements (WSE) could be used along with ASMX to communicate with the J2EE-based reservation application and with the partner applications. Because it implements more recently defined Web services agreements, known collectively as the WS-* specifications, WSE can allow better security and more, as long as all applications involved support compatible versions of these new specifications.

·         Microsoft Message Queuing (MSMQ) could be used to communicate with Windows-based partner applications that weren’t always available. The persistent queuing that MSMQ provides is typically the best solution for intermittently connected applications.

WCF can be used for all the situations described above. Here’s how WCF addresses each of these requirements:

·         Because WCF can communicate using Web services, interoperability with other platforms that also support SOAP, such as the leading J2EE-based application servers, is straightforward.

·         To allow optimal performance when both parties in a communication are built on WCF, the wire encoding used in this case is an optimized binary version of SOAP. Messages still conform to the data structure of a SOAP message, referred to as its Infoset, but their encoding uses a binary representation of that Infoset rather than the standard angle-brackets-and-text format of XML. Using this option would make sense for communicating with the call center client application, since it’s also built on WCF, and performance is a paramount concern.

·         Managing object lifetimes, defining distributed transactions, and other aspects of Enterprise Services are now provided by WCF. They are available to any WCF-based application, which means that the rental car reservation application can use them with any of the other applications it communicates with.

·         Because it supports a large set of the WS-* specifications, WCF helps provide reliability, security, and transactions when communicating with any platform that also supports these specifications.

·         WCF’s option for queued messaging, built on MSMQ, allows applications to use persistent queuing without needing to use another set of application programming interfaces.

 

The result of this unification is greater functionality and significantly reduced complexity. Because WCF allows an application to address all the communication requirements listed earlier, it can easily support scenarios that were difficult (or even impossible) with the collection of technologies that preceded it.

Thursday, June 26, 2008 5:41:17 AM (GMT Standard Time, UTC+00:00)  #    Comments [0]   C#  | 
Copyright © 2009 Software Code Help. All rights reserved.
DasBlog 'Portal' theme by Johnny Hughes.
Pick a theme: