jump to navigation

Refactoring tool of Visual Studio 2005 September 7, 2007

Posted by addisu in Software - .NET 2.0, Software - .NET General, Software - ASP .NET 2.0, Software - C#.
1 comment so far

How much do u use refactoring tool of Visual Studio 2005?

  • Rename: i probably use this tool more often. Once you declare a class or a variable and used it everywhere, “rename” tool is the best if you are not happy with the name. Naming is one of best practice and the name of a class or a variable should be descriptive. You might not come up with the best name at the beginning.
  • Extract Method: This is another tool i use. Every time there is a reusable portion of code that exist in my method, i used “Extract Method” to have another smaller method. … for two purposes sometimes,..one to reuse the code and two, to make smaller size and readable method
  • Generate Method Stub: even though it is not part of the Refactoring tool part, i like to use this tool. I write a method call to an object that doesn’t exist. I use this tool to generate the method stub. The best part of this tool is, it knows if private or internal or public should be used. … the name and type of parameter, return value…

Using keyword “using” in code block March 3, 2007

Posted by addisu in Software - .NET 2.0, Software - .NET General, Software - ASP .NET 2.0, Software - C#.
2 comments

Recently, I have been asked about the alternative way to Dispose objects as we often do in the “finally” block in “Try .. Catch .. Finally” block for connection object. I have seen “using” keyword in some sample codes but I never aware of it does dispose the objects declared as “using

Example:

using (IDataReader dataReader = _db.ExecuteReader(“GetCategories”))
{
// Processing code
while (dataReader.Read())
{
Category item = new Category(
dataReader.GetInt32(0),
dataReader.GetString(1),
dataReader.GetString(2));
this.cmbCategory.Items.Add(item);
}
}

  1. One thing to note is the objects inside the “using” block should implement “IDisposable” interface.
  2. Still if we want to cache Exception, we need to inside and for me it seems a little bit redundant if we do the dispose inside the “finally” block as we often do for the connection object

Use authorization to establish the rights of an authenticated user in ASP .NET December 8, 2006

Posted by addisu in MCPD Web Developer, Software - .NET 2.0, Software - .NET General, Software - ASP .NET, Software - ASP .NET 2.0, Software - Certifications.
add a comment
  • Manage roles in the Web Site Administration Tool.
  • Ascertain whether a specific user is in role.
  • Get the roles for a specific user by using the Roles object or the User object.
  • Store role information in a cookie.
  • Restrict access to files by using file authorization.
  • Restrict access to portions of an application by using URL authorization.

Summary

The Web Site Administration Tool allows you to manage roles and add users to roles on the security tab.

You can use the Roles Object static method IsUserInRole to determine if a user is a member of a role.

You can get the roles for a specific user by using the GetRolesForUser method of the Roles Object.

You can configure the RoleManager in the web config of the application to store a users role information in a cookie.

To apply authorization rules to a specific file or folder, enclose the <authorization> element inside a <location> element as shown here. The example of how to restrict access to portions of an application using URL authorization is from the resource Security Practices: ASP.NET 2.0 Security Practices at a Glance

<location path="Secure" >

  <system.web>

    <authorization>

      <deny users="?" />

    </authorization>

  </system.web>

</location>

Other Resources & Links:

Web Site Administration Tool Security Tab
http://msdn2.microsoft.com/en-us/library/ssa0wsyf.aspx

Roles Class
http://msdn2.microsoft.com/en-us/library/system.web.security.roles(VS.80).aspx

MembershipUser Class
http://msdn2.microsoft.com/en-us/library/system.web.security.membershipuser(VS.80).aspx

How to Use Role Manager in ASP.Net 2.0
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag2/html/paght000013.asp

Security Practices: ASP.NET 2.0 Security Practices at a Glance
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag2/html/PAGPractices0001.asp

Forms Authentication for ASP .NET Sub-Directories
http://www.theserverside.net/tt/articles/showarticle.tss?id=FormAuthentication

Establish a user’s identity by using forms authentication in ASP .NET 2.0 December 8, 2006

Posted by addisu in MCPD Web Developer, Software - .NET 2.0, Software - .NET General, Software - ASP .NET 2.0, Software - Certifications.
add a comment
  • Configure forms authentication for a Web application by using a configuration file.
  • Enable cookieless forms authentication by setting the cookieless attribute.
  • Use membership APIs and the Membership class to manage users.
  • Enable anonymous identification.

Summary

The following description of how to configure forms authentication is from msdn:

To implement forms authentication you must create your own logon page and redirect URL for unauthenticated clients. You must also create your own scheme for account authentication. The following is an example of a Web.config configuration using Forms authentication:

<!-- Web.config file -->

<system.web>

   <authentication mode="Forms">

      <forms forms="401kApp" loginUrl="/login.aspx" />

   </authentication>

</system.web>

Because you are implementing your own authentication, you will typically configure IIS for Anonymous authentication.

The forms node has an attribute that is new to .Net 2.0: Cookieless. It has four values: UseUri – Store the authentication ID in the url, UseCookies, AutoDetect, and UseDeviceProfile which looks up the device in machine config to determine whether to use cookies or not.

The Membership class can be used to create new users, store user data (user names, passwords, e-mail addresses, and supporting data), authenticating users either programmatically or with the Login controls provided by ASP.Net, and managing passwords for users.

 The following description of how to enable anonymous identification is from msdn:

ASP.NET 2.0 supports anonymous identification, and you can encrypt the anonymous identification cookie. Encryption of the cookie uses the <machineKey> configuration. To enable anonymous identification, set enabled=”true” on the <anonymousIdentification> element in your Web.config file. To enable the cookies to be encrypted, set cookieProtection=”Encrypted”, as shown here.

<anonymousIdentification enabled="true" cookieName=".ASPXANONYMOUS"

cookieTimeout="100000" cookiePath="/" cookieRequireSSL="false"

cookieSlidingExpiration="true" cookieProtection="Encrypted"

cookieless="UseCookies" domain="" />

Other Resources & Links:

ASP.Net Authentication
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsent7/html/vxconASPNETAuthentication.asp

ASP.Net 2.0 Security (Has info on cookieless forms authentication)
http://www.awprofessional.com/articles/article.asp?p=351414&seqNum=4&rl=1

Membership Class
http://msdn2.microsoft.com/en-us/library/system.web.security.membership(VS.80).aspx

How To: Configure MachineKey in ASP.NET 2.0 (Has info on configuring Anonymous Identification)
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag2/html/paght000007.asp

Implement Web Parts in a Web application in ASP .NET 2.0 December 7, 2006

Posted by addisu in MCPD Web Developer, Software - .NET 2.0, Software - .NET General, Software - ASP .NET 2.0, Software - Certifications.
add a comment
  • Track and coordinate all Web Parts controls on a page by adding a WebPartManager control.
  • Connect Web Parts to each other by using connection objects.
  • Divide a page that uses Web Parts into zones by using WebPartZones.
  • Present a list of available Web Parts controls to users by using CatalogPart controls.
  • Enable users to edit and personalize Web Parts controls on a page by using EditorPart controls.

Summary

New  to ASP.Net 2.0 are the concept of web parts, customizable modular data presentation components.

The WebPartManager Class is used to manage all the Web Parts on a page and their events. This class is the workhorse for all web part functionality. The following details on what this control does are taken from MSDN:

The WebPartManager control acts as the hub or control center of a Web Parts application. There must be one–and only one–WebPartManager control instance on every page that uses Web Parts controls. As with most aspects of Web Parts applications, the WebPartManager control works only with authenticated users. Further, its functionality works almost entirely with server controls that reside within Web Parts zones that inherit from the WebZone class. Server controls that reside on a page outside of these zones can have very little Web Parts functionality or interaction with the WebPartManager control.

As the hub for Web Parts functionality on a page, the WebPartManager control carries out the kinds of tasks listed below

Tracking Web Parts controls
Keeps track of the many different kinds of controls on a page that provide Web Parts features, including WebPart controls, connections, zones, and others.

Adding and removing Web Parts controls
Provides the methods for adding, deleting, and closing WebPart controls on a page.

Administering connections
Creates connections between controls, and monitors the connections as well as the processes of adding and removing them.

Personalizing controls and pages
Enables users to move controls to different locations on a page, and launches the views in which users can edit the appearance, properties, and behavior of controls. Maintains user-specific personalization settings on each page.

Toggling between different page views
Switches a page among different specialized views of the page, so that users can carry out certain tasks such as changing page layout or editing controls.

Raising Web Parts life-cycle events
Defines, raises, and enables developers to handle life-cycle events of Web Parts controls, such as when controls are being added, moved, connected, or deleted.

Enabling import and export of controls
Exports XML streams that contain the state of the properties of WebPart controls, and allows users to import the files for convenience in personalizing complex controls in other pages or sites.

The following explanation of connecting Web Parts comes from the Personalizing Using Web Parts ASP.Net Quickstart Tutorial:

Web parts are also capable of exchanging data between them, using web part connections. Using connections, you can have one web part provide one or more property values that can be used by other web parts on the page. Web part connections have the following elements:

An interface that defines the communications contract between two parts. The interface describes properties and methods available through the connection.

A web part that behaves as a connection provider. To specify a provider connection point, a web part needs to have a method that creates and returns an instance of the communications interface. This method should be marked with the ConnectionProvider attribute. By default, A single provider connection point can be used with multiple connection consumers.

A web part that behaves as a connection consumer. To specify a consumer connection point, a web part needs to have a method that takes an instance of the communications interface as a parameter. This method should be marked with the ConnectionConsumer attribute. By default, A single consumer connection point can only be used with one connection provider.

WebPartZones define the areas on the page where Web Parts can be placed and also define common user interface for those controls by defining styles.

The CatalogPart Control is used to list the controls that a user can add to a web page.

The EditorPart Control is used to modify web parts when they are in edit mode.  Using this control you can modify its layout, appearance, properties, behavior, or other characteristics.

Other Resources & Links:

Personalize Your Portal with User Controls and Custom Web Parts
http://msdn.microsoft.com/msdnmag/issues/05/09/WebParts/default.aspx

Personalizing Using Web Parts – ASP.NET Quickstart Tutorials
http://www.asp.net/QuickStart/aspnet/doc/webparts/default.aspx

WebPartManager Class
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.webparts.webpartmanager(VS.80).aspx

WebPartConnection Class
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.webparts.webpartconnection(VS.80).aspx

WebPartZone Class
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.webparts.webpartzone(VS.80).aspx

Catalog Part Class
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.webparts.catalogpart(VS.80).aspx

EditorPart Control
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.webparts.editorpart(VS.80).aspx