Sunday 27 September, 2009

How to Generate Sequence Diagram online


How to Generate Sequence Diagram online
Don't wast your time to create sequence diagram using visio or some
other tools.
Here I found very useful site that generates sequence diagram as per
your requirement.
You have to just type very smple script that should descripe the call
from one class to
another and On click of "Draw" button you can get your secquence diagram
in the form of picture or pdf.
Don't worry about script learning and script notation, it's
very,following site will give you all help and example
pink back from :
http://www.websequencediagrams.com/

Formatting numeric data types in .NET

Formatting for decimal places.
Formatting numbers.
Formatting numbers using # symbol.
Formatting for thousand separator.
Formatting for positive and negative numbers.
Multiplying a number by 100.
Appending currency symbol to a number.
Displaying numbers in exponential form.


Thanks to Sandeep for Sharing Such formatters......

Methods in Global.asax


It’s very important to understand the methods in global.asax so that we as programmers can handle some application level events very efficiently. I said application level events and reason for using application word is that global.asax is an application level file and methods in it are used to handle application level events and these methods are not at all specific to any aspx page. Some of the common methods in the order in which they are executed are listed below
  • Application_Start
  • Application_BeginRequest
  • Application_AuthenticateRequest
  • Session_Start
  • Application_EndRequest
  • Session_End
  • Application_End
  • Application_Error
PingBack from Methods in Global.asax

Configuring Machine Key in ASP.NET 3.5 to tamper proof viewState

Security is a major concern when it comes to online transactions like shopping. Today we will learn how to tamper proof your ASP.NET application using element in web.config file. How to protect your sensitive ViewState data and Forms authentication ticket.

By default, ViewState in ASP.NET is encoded and not encrypted as you might feel. ViewState is transmitted to server as a Base64 string and can be easily decoded.Take a look at this if you are interested in decoding stuff and read more about Base64 here.

Encrypting and protecting ViewState: For a tamper proof ViewState a hashed message authentication code (HMAC) is generated from ViewState data which is then compared on subsequent requests. We can make use of element and can encrypt our ViewState using desired encryption mechanisms. Eg, SHA1 , MD5, AES and 3DES. Here is how a element looks but before that we need to set enableViewStateMac=True in our asp.net page as shown below code segment.
<%@ Page  EnableViewStateMac="true" ViewStateEncryptionMode="Auto"  Language="C#" AutoEventWireup="true" CodeBehind="login.aspx.cs" Inherits="Using_SQL_Membership.login" %>

Or you can set it in web.config file as shown below.


enableViewState=True enables hashing of viewstate while you viewStateEncryptionMode takes 3 values. Auto, Always and Never. With viewStateEncryptionMode set to Auto, the page is only encrypted if a control has specifically asked for it by calling the Page.RegisterRequiresViewStateEncryption() method to request encryption. If it set to Always, this forces encryption even if a control does not request it. For performance reasons do not encrypt viewState unless and until it has sensitive data.



1. validationKey: This specifies the key that the HMAC algorithm uses to make ViewState tamper proof.

2.decryptionKey: specifies the key used to encrypt or decrypt data. Also, ASP.NET uses the key only if validation attribute is set to AES or 3DES.

3.validation: specifies the hashing algorithm used to generate HMACs to make ViewState encrypted.

In general, you should choose SHA1 over MD5 for tamper-proofing because this produces a larger hash than MD5 and is considered cryptographically stronger.

Encrypting and protecting Forms Authentication:

To ensure that forms authentication tickets are encrypted and protected against tampering, set the protection attribute of the element to All, as shown


Along with this make same settings to machineKey as shown above.

If you deploy your application in a Web farm, you must ensure that the configuration files on each server share the same value for validationKey and decryptionKey, which are used for hashing and decryption respectively. This is required because you cannot guarantee which server will handle successive requests.

Viewing ASP.NET viewstate with ViewState Decoder
Do you ever wonder what may be inside that asp.net viewstate? As a tester don't you think you should? It's a good thing to wonder about if you care about security. It's possible that the viewstate could contain sensitive user information that could be compromised in a man in the middle attack. For example: A user can input a credit card number into a textbox which would be passed to the next page via the viewstate. Not good... The viewstate is not encrypted by default its just simple Base64 encoding which can easily decoded with cool little tools like ViewState Decoder made by Fritz Onion.

ASP.NET View State


What is a view state?
View state in simple terms can be defined as a way to maintain the state of an aspx page during postbacks. And this is the no 1 one liner answer I get from candidates during interviews. Viewstate is a technique which helps in retaining the values of the controls placed in a page during postback/roundtrip. With this blog, again, my aim is the same, to spread more light on what is view state all about.


What do you mean by state of an aspx page?
The state of an aspx page means the values of the controls in an aspx page. By default the view state is maintained for all the controls which are placed in an aspx page. The state of a control can be the text entered in a text box, the checked status of a radio button or check box, the content and selected item in a drop down control etc.



Where is view state stored?
View state is stored in the client in the form of a hidden control called “__VIEWSTATE”. Here by client I mean the rendered aspx pages in the browser. If view state property is set to true then ASP.NET automatically adds a hidden field/control by the name “__VIEWSTATE” and stores the information related to the state of the page in an encrypted format.


What is the encoding used in view state?
View state is stored in base64 format. The base64 format can generate huge amount of data on conversion and this is the reason we are adviced to use view state judiciously.



Which class handles view state?
StateBag class handles the view state and it implements a Dictionary to keep track of the changes in a form. The developer can add or remove items from this dictionary as you would from any dictionary object. You can access this class through the Control.ViewState property.


Can view state be stored in multiple hidden fields?
Yes, view state can be stored in multiple hidden fields. This can be achieved by setting the page’ “MaxPageStateFieldLength” property. If the property is set to a positive value then the view state is broken and sent to the client in multiple hidden field and each field’ size will be less than the value spedified in “MaxPageStateFieldLength”.



How to disable view state?
View state can be disabled in the following ways.



1. In machine.config – you can disable view state for all the application hosted in the server by modifying the following tag in machine.config as shown below.

2. Application/website level - if you want to disable view state for all the pages in your application then you can do that in web.config file as shown below.


3. Page level – you can use this option to switch off the view state for all the controls in a web page by setting the “EnableViewState” page attribute

4. Control level - you can switch off a control’ view state by setting the EnableViewState property of the control to false from property window or as shown below.


Hope the above details give a clearer picture on what view state is. There is more to view state than what is written here.


Microsoft Releases Charting Control as VS2008 Add-on

As you may (or may not) know, a while back Microsoft purchased some charting functionality from Dundas, to be included as part of Reporting Services for SQL Server 2008. Well, now they have packaged up this functionality as a control for Visual Studio 2008! This is a fantastic add-on, as we now have the power, flexibility, and visual excellence of the old Dundas chart control as a free Visual Studio 2008 add-on!


Scott Guthrie has an excellent blog post discussing it, which can be found here.


Scott specifcially talks about ASP.NET, and a few of the commenters on his blog ask the obvious question: Can this be used for Winforms apps as well? I went ahead and installed the add-on, and the new Chart control can indeed be dropped into Winforms apps as well as ASP.NET!


Lastly, I got curious as to whether or not this control could be used from Visual Studio 2005. It doesn’t show up in the toolbox automatically, but it can be added and does indeed work in VS2005!




In addition to the above samples, you can download the Microsoft Chart Control Documentation





Simple tips: Set Focus to TextBox in GridView (edit mode)


If you use TemplateField like


            
                
             
            
                
             
        


 You could do it in RowEditing, for example:

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {
            //Normal turning to edit
            GridView1.EditIndex = e.NewEditIndex; 
            BindGrid();

            //Set the focus to control on the edited row
            GridView1.Rows[e.NewEditIndex].FindControl("txtEdit").Focus();
        }

I'm binding the grid manually, therefore there is setting the index and calling databinding functions. However, with BoundField (I have CommandField as left most column) it could be something like:

GridView1.Rows[e.NewEditIndex].Cells[1].Controls[0].Focus();

where Cells[index] is the one you should be modifying based on which column it is in question (still doing in RowEditing)
In case you use data-source controls, it might be feasible to do it in RowDataBound:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowState == DataControlRowState.Edit)
            {
                //Set the focus to control on the edited row
                e.Row.Cells[1].Controls[0].Focus(); 
                //Or to a specific control in TemplateField
               // e.Row.FindControl("txtEdit").Focus(); 
            }
        } 

Windows Media Player and Music Status In Gtalk


A post From Google Talk groups (Google) , i thot this wil be useful for most of the gtalk users who are searching for this issue for a long time ….
Hi everyone,
I just wanted to add a little something about an
issue that sometimes comes up when users are trying to share their
music status in Google Talk using Windows Media Player.
When Windows Media Player or your Windows desktop crashes, Windows
Media Player is designed to disable all plug-ins (including the Google
Talk music status plug-in). If this happens, the current music track
you’re playing on Windows Media Player won’t show up as your Google
Talk’s status message.
I know many of you have found the solution to this problem, but for
those who haven’t found this fix before, all you need to do is
re-enable the Google Talk plug-in. Just follow these steps:


1. Open Windows Media Player.
2. From the View menu, select ‘Plug-ins’ > ‘Options…’
3. From the Category section of the Plug-ins tab, select ‘Background.’
4. Select the ‘Google Talk Music Plugin’ checkbox.
5. Click ‘OK.’
You’ll have to close and restart Windows Media Player for your change
to take effect. 

But sometimes the problem started when I tried to used in WMP 11 on Windows Vista Home Premium ...
this is for vista! 
INSTALLING GTALK AND MEDIA PLAYER DISPLAYING THE TRACKS.
all you have to do is right click your gtalk installer. before that close both your media player and gtalk, it doesnt matter if you installing the same version. instead of clicking on install, you RUN AS ADMINISTRATOR. wait a little, open you gtalk, choose to show current track, run your windows media player and play a track, now the media file`s name should be displayed.
cheers.

Happy music status sharing!

Thursday 10 September, 2009

Visual Studio Add-Ins Every Developer Should Download Now

Visual Studio provides a rich extensibility model that developers at Microsoft and in the community have taken advantage of to provide a host of quality add-ins. Some add-ins contribute significant how-did-I-live-without-this functionality, while others just help you automate that small redundant task you constantly find yourself performing.

TESTDRIVEN.NET :
Test-driven development is the practice of writing unit tests before you write code, and then writing the code to make those tests pas

GHOSTDOC :
XML comments are invaluable tools when documenting your application. Using XML comments, you can mark up your code and then, using a tool like nDoc, you can generate help files or MSDN-like Web documentation based on those comments. The only problem with XML documentation is the time it takes to write it you often end up writing similar statements over and over again

SMART PASTER:
The Smart Paster add-in helps to limit some of this by providing a number of commands on the right-click menu that let you paste a string from the clipboard into Visual Studio using a certain format. After installing Smart Paster, you will see the new paste options available on the right-click menu.

CODEKEEP:
CodeKeep is a Web application that provides a place for people to create and share snippets of code in any language. The true usefulness of CodeKeep is its Visual Studio add-in, which allows you to search quickly through the CodeKeep database, as well as submit your own snippets.

PINVOKE.NEThttp://www.pinvoke.net/ :
PInvoke.NET is a wiki that can be used to document the correct P/Invoke signatures to be used when calling unmanaged Win32 APIs. A wiki is a collaborative Web site that anyone can edit, which means there are thousands of signatures, examples, and notes about using P/Invoke.

VSWINDOWMANAGER POWERTOY :
VSWindowManager will automatically switch between the design and coding layouts depending on whether you are currently viewing a designer or a code file. You can also use the commands on the Apply Window Layout menu to choose from your currently saved layouts. When you select one of the layouts you have saved, VSWindowManager will automatically hide, show, and rearrange windows so they are in the exact same layout as before.

WSCONTRACTFIRST:
WSContractFirst makes it easier to write your WSDL file, and will generate client-side and server-side code for you, based on that WSDL file.

VSMOUSEBINDINGS :
VSMouseBindings makes extensive use of the command pattern. You can bind mouse buttoms to various commands, such as open a new file, copy the selected text to the clipboard, or just about anything else you can do in Visual Studio.

COPYSOURCEASHTML:
After installing the CopySourceAsHTML add-in, simply select the code you want to copy and then select the Copy Source as HTML command from the right-click menu .

CACHE VISUALIZER :
ASP.NET Cache represents a collection of objects that are being stored for later use. Each object has some settings wrapped around it, such as how long it will be cached for or any cache dependencies. There is no easy way while debugging to get an idea of what is in the cache, how long it will be there, or what it is watching. Brett Johnson saw that gap and wrote Cache Visualizer to examine the ASP.NET cache.

WRAPPING IT UP:

While this article has been dedicated to freely available add-ins, there are also a host of add-ins that can be purchased for a reasonable price. I encourage you to check out these other options, as in some cases they can add some tremendous functionality to the IDE. This article has been a quick tour of some of the best freely available add-ins for Visual Studio. Each of these add-ins may only do a small thing, but together they help to increase your productivity and enable you to write better code.

Wednesday 9 September, 2009

How to add syntax highlighting to Blogger with Alex Gorbatchev's open-source SyntaxHighlighter.

How to display code (nicely) in Blogger posts
I’ve long been envious of all those blogs that show code, nicely formatted and even with line numbers! I finally found out how it’s done.

How to add syntax highlighting to Blogger with Alex Gorbatchev's open-source SyntaxHighlighter.
1.Log into your blogspot account, select the "Layout" tab, and then click "Edit HTML."
2.Click "Download Full Template" to make a backup of your current template.
3.Make a copy of your template, open it in an editor, and find the </head> closing tag. Before that tag, add the following:

<link href='http://alexgorbatchev.com/pub/sh/current/styles/shCore.css' rel='stylesheet' type='text/css'/>
<link href='http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css' rel='stylesheet' type='text/css'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js' type='text/javascript'/>
<!-- add brushes here -->
<script type='text/javascript'>
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.all();
</script>


4.After the comment that says "add brushes here," add the languages you plan to use.
For example, I'm using brushes for Javascript, CSharp, SQL, XML/HTML, and C++:

<!-- add brushes here -->
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCSharp.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushSql.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCpp.js' type='text/javascript'/>


5.See the full list of supported syntaxes.

6.Save your modified template, and upload it to Blogger (again, under Layout > Edit HTML).

You should now be able to add syntax highlighting to your blog. Wrap your code in a <pre> tag and specify the brush to use in the class attribute. For example, to highlight a block of SQL:


SELECT *
FROM users
WHERE user_id = 1212;


6.If Blogger produces an Error message, saying something like a tag isn't allowed, simply click the checkbox to ignore, and hit Publish Post.

7.All thanks goes to Alex Gorbatchev for creating Syntax Highlighter in the first place. If you want to speed up things, you might want to host the Syntax Highlighter files on your own webspace (such as on a free webhost; just google).

8.If you don't care about fancily presented code and just want the job done, visit the HTML Entities Encoder and simply copy-paste...:)

HAPPY CODING :)