C Tip



How do I write code that reads the segment register settings?

Ans: We can use segread( ) function to read segment register settings. There are four segment registers—code segment, data segment, stack segment and extra segment. Sometimes when we use DOS and BIOS services in a program we need to know the segment register's value. In such a situation we can use segread( ) function. The following program illustrates the use of this function.

#include <dos.h>
main( )
{

struct SREGS s ;
segread ( &s ) ;
printf ( "\nCS: %X DS: %X SS: %X ES: %X",s.cs, s.ds, s.ss, s.es ) ;

}

Top


C++ Tip



What is strstream?

Ans: strstream is a type of input/output stream that works with the memory. It allows using section of the memory as a stream object. These streams provide the classes that can be used for storing the stream of bytes into memory. For example, we can store integers, floats and strings as a stream of bytes.
There are several classes that implement this in-memory formatting. The class ostrstream derived from ostream is used when output is to be sent to memory, the class istrstream derived from istream is used when input is taken from memory and strstream class derived from iostream is used for memory objects that do both input and output.

Top


VC++ Tip



How do I write code that displays a progress control while copying contents?

Ans: Use SHFileOperation( ) function as shown below:

void MyDlgdlg::OnCopy( ) 
{

SHFILEOPSTRUCT s ;
::ZeroMemory ( &s, sizeof ( s ) ) ; // Initialize the structure

CString f = "C:\\MyFolder" ;
CString t = "D:\\" ;

char from [ MAX_PATH ], to [ MAX_PATH ] ; // buffer used to copy source and target path

strcpy ( from, f ) ;
int l = f.GetLength( ) ;
from[l+1] = '\0' ; 

strcpy ( to, t ) ;
l = t.GetLength( ) ;
to[l+1] = '\0' ;

// Set the values in structure
s.hwnd = this -> m_hWnd ;
s.wFunc = FO_COPY ;
s.pFrom = ( LPCTSTR ) from ;
s.pTo = ( LPCTSTR ) to ;
s.fFlags = FOF_SIMPLEPROGRESS ;
s.lpszProgressTitle = "Copying files..." ;

::SHFileOperation ( &s ) ;

}

Top


C# Tip



How do I write code to display tool tip for controls?

Ans: We can display a tool tip for any control placed on a form. For this, we have to add a ToolTip control to the form. As soon as we add the ToolTip control a property named 'Tooltip on tip' gets added to the 'Properties' window of all the controls placed on the form. The string entered against this property gets displayed as the tool tip when mouse is moved over the control. How come only one ToolTip control manages to display tips for all the controls for which 'Tooltip on tip' property is set? When we set the 'Tooltip on tip' property of a control, a call to the ToolTip.SetToolTip( ) method gets added in the InitializeComponent( ) method as shown below:

tip.SetToolTip ( button, "This is a Button" ) ;

The reference to the control (in this case, button) is passed to the SetToolTip( ) method along with the tool tip text. The SetToolTip( ) method associates the text with the specified control.

 Top


VB.NET Tip



How do I write code that shows check boxes in the list view and displays the text in a message box when a check box is checked?

Ans: Create a Windows application and place a list view control named as list on the form. Set its ShowCheckBoxes property to true and view property as List. Add items in the list by clicking on Items property in the 'Properties'. Set the Text property of each item in the 'ListViewItem Collection' editor. To be able to make use of ListviewCollection class write following statement in  Form1.vb at the top.

Imports System.Windows.Forms.ListView

Now, add ItemCheck event handler of list and write following code in the ItemCheck event handler.

Private Sub list_ItemCheck ( ByVal sender As Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs )

Handles list.ItemCheck

Dim icoll As ListViewItemCollection = list.Items
Dim litem As ListViewItem = icoll.Item ( e.Index )

If e.NewValue = CheckState.Checked Then
MessageBox.Show ( litem.Text )
End If

End Sub

Top


Article: C#- ASP.NET security



ASP.NET security is mostly concerned with building secured sites that serve up pages only to authorized users. There are certain sites on the net that require login before displaying certain pages. These sites must implement some application level security to identify authorized users. This application-level security is provided using ASP.NET. It works in conjunction with IIS, the .NET platform and the underlying operating system security services. 

Whenever a client tries to connect to a website, it has to make a request to the Web Server for a particular page. This request is known as a webrequest. To implement the security at application level, the application needs to take two actions—identify the person who has made the request to the web server and specify who can access which pages.

This action of identifying the caller of web page is known as authentication. Once authentication is done, it is decided which pages the caller can view. This is known as authorization. ASP.NET supports four types of authentication and authorization mechanisms. 

  - Windows authentication
  - Passport authentication
  - Forms authentication

Let us discuss them one by one.

Windows Authentication

This type of authorization is best suited for intranet applications. A user will be able to access a requested resource only if he has a valid and active account on Windows. Moreover that account needs to have permissions to access the specific resource. This type of authentication is very secured since it uses hash algorithms to encode and decode client’s credentials. However there are a few problems, this type of authentication does not work through most proxy servers, firewalls, and some routers. Hence this technique is not very suitable for Internet applications.

Setting up Windows authentication is simple. Just make the following settings in the ‘web.config’ file of your project.

<configuration>

<system.web>

<authentication mode="Windows" /> 
<identity impersonate="true" />

<system.web />

<configuration />

These entries ask ASP.NET to use Windows authentication with Identity impersonation for the authentication. Simply doing this will not work if IIS is configured to accept anonymous requests to this website (by default IIS accepts anonymous requests to any Website). To turn off anonymous access to this site, follow the instructions given below.

  (a) Start Internet Services Manager from Administrative tools in the Control Panel.
  (b) In the IIS, explore the branch with name same as your local machine name.
  (c) Explore ‘Default WebSites’.
  (d) Locate the Website we want to authenticate using Windows authentication.
  (e) Right click on it and select Properties. Property pages would get displayed.
  (f) Select the tab named ‘Directory Security’
  (g) Click on the edit button inside the group box named Anonymous access and authentication control
  (h) In the following dialog, uncheck Anonymous access check box. Make sure Integrated Windows Authentication check box
       is checked.
  (i) Click OK to dismiss the dialogs.
     
This process will force IIS to pop up Windows authentication dialog before displaying the web page requested.

This can be done programmatically by modifying the <authorization> section of the web.config file. Make the following changes to the authentication section

<configuration>

<system.web>

:::
<authorization>

<deny users="?" />

</authorization>
:::

</system.web>

</configuration>

We instruct IIS to not to allow any users without proper authentication. The tag deny users=”?” will stop all unauthenticated users from accessing the website.

Passport Authentication

Passport authentication is a service provided by Microsoft. This service allows us to implement single SignIn for multiple applications or Websites that want to authenticate users. The user is expected to use only one user name and password to access all the sites more over, the user need not re-SignIn whenever he switches from one site to another (provided both sites support Passport authentication). For example, if site1.com and site2.com both support passport authentication, then if a user visits site1.com, sign in the site and then decide to visit site2.com, you will be automatically authenticated on the basis of the credentials you presented at site1.com. This is possible because whenever you sign into a Passport service supporting site, the service creates a secure cookie into our machine. Later when we visit another Passport supporting site, our browser presents this cookie. This cookie indicates that we have already been authenticated and no new authentication is required. To setup Passport authentication, following configuration needs to be added to the ‘web.config’ file.

<configuration>



<system.web>

<authentication mode="Passport" > 
<Passport redirectUrl="internal|url" />
<authentication />

<system.web />

<configuration />

But Passport service is not free. If we want to support Passport authentication on our website, we will have to subscribe to it. 

Forms Authentication

Form based Authentication is best suited where very high degree of security is not required. We can use our own login form, replacing the default login provided by Windows. In almost all situations we will allow anonymous access to our website, since authentication is done by ASP.NET instead of IIS. 

ASP.NET first checks whether there is any authentication cookie present in the request header. If cookie is present, we know that the user is already authenticated and his identity is present in the cookie. Otherwise the user is automatically redirected to our custom login page. The user then presents his login credentials. If the user is authenticated, we place a cookie in the request header and pass it on to ASP.NET other wise access is denied. 

Form based authentication is configured in the ‘web.config’ file. The <authentication> section carries information regarding cookies, password formats, list of registered users, etc.

Top


Joke



This notice was pasted on an electrical-power panel: "Only Authorized Personnel Will Replace Fuses." Underneath someone had scribbled: "Other personnel will not fit."

Top


Different Strokes





An Illusion!

Top