Pages

Invoking mouse events through JavaScript

Handling Mouse Events through Java script

In some scenarios, we may need to invoke a button click through script. We can write element.click(), but that will not work in all the browsers. We may need to do this in another way, please check the below code snippet.


function invokeSaveClick(saveElementId) {
    var e = document.createEvent('MouseEvents');
    e.initEvent('click', true, true);
    document.getElementById(saveElementId).dispatchEvent(e);
}

Request.ApplicationPath is not working in some cases

Request.ApplicationPath will work only IE. When we want to support different browsers like Chrome, Safari and Firefox, we should use the below property to get the correct relative URL.
this.Request.Url.GetLeftPart(UriPartial.Authority)
Example:

If we use Request.ApplicationPath 
window.open('" + Request.ApplicationPath + "/abc/testpage.aspx?x=1"','test page', 'toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes ,modal=yes'); }", true); 
It will be rendered as http://abc/testpage.aspx?x=1

If we use Request.Url.GetLeftPart(UriPartial.Authority), then it will be rendered as 
http://ServerName/abc/testpage.aspx?x=1



View State Issues in ASP.Net


We are getting some of the view state related errors in our application.
  • Invalid view state.
  • Unable to read beyond the end of the stream.
  • The serialized data is invalid.
  • The client disconnected.
The reason for this errors are one of the one mentioned below:

1. The application may be deployed across farms and the encryption/Decryption keys may vary in the servers, so it may throw errors intermittently.
2. The View state may be very large or bloated, so it may reduce the application performance and may cause issue while serialization or deserialization of View state.

Possible solution for this issue are,

1. We can set the encryption validation key at the application level in the web.config file. It looks like the one mentioned below.

<machinekey decryption="AES" decryptionkey="4C05D6B56FA0A057F519884A1C3B5B42B14491ED56CB44F942EE3A0CA2848D29" validation="SHA1" validationkey="ABFD56FE84823AE69E9A613CE998803F4246FE0D96DC48E7BB9E715B0A57352CEFB35264EFB8C0F710E154F42B7460B7CDE9A99F225DA796DEE5E5F94F8F7188"></machinekey>


We can generate keys online from this location. http://aspnetresources.com/tools/machineKey

<pages enableviewstatemac="true">

We can also set the enableViewStateMac to true, but we have some issues when we implement the both these fixes. It may throw user a run time error or compiler warning. It will not allow you to debug sometimes.

3. Other simple solution to overcome this issue is to break the view state in to multiple chunks so that we can avoid the serialization error. This can be achieved by setting a simple property in the pages element of config file.

<pages maxpagestatefieldlength="20">


4. We can also compress and decompress the view state using a simple logic and have that code in the Base Page of the application. We can use compression at the page level by setting a property. Please check the code project link for a detailed explanation on this.

http://www.codeproject.com/KB/viewstate/ViewStateCompression.aspx

These are some of the things I found during my search, i put all the points in one stop for your reference. It worked for me. Hope the same for you all.

Blind SQL Injection

SQL Injection can be avoided using HTML encoding. Please find the list of characters which needs to be handled which getting user inputs especially in multi-line text boxes.

[1] | (pipe sign)
[2] & (ampersand sign)
[3] ; (semicolon sign)
[4] $ (dollar sign)
[5] % (percent sign)
[6] @ (at sign)
[7] ' (single apostrophe)
[8] " (quotation mark)
[9] \' (backslash-escaped apostrophe)
[10] \" (backslash-escaped quotation mark)
[11] <> (triangular parenthesis)
[12] () (parenthesis)
[13] + (plus sign)
[14] CR (Carriage return, ASCII 0x0d)
[15] LF (Line feed, ASCII 0x0a)
[16] , (comma sign)
[17] \ (backslash)

Their is always a chance of manupulating the SQL script as part of form inputs and also end user can prepare a request dynamically and hit the target url's. If we use the HTML encode and decode this can be avoided.

Example:

While getting the input values from the form and before processing that. 
string data = HTTPUtility.HTMLEncode(Textbox1.Text)
While rendering the data to UI 
Textbox1.Text = HTTPUtility.HTMLDecode(data)
This is simple and one of the best practice to avoid SQL injection.




Cross Site Scripting : Validating Query string parameters string

1. We need to validate the request by setting the ValidateRequest="true" on the @ Pages element.

2. We need to take care while using query string parameter. We need to cast the query string value to the respective data type to avoid this. Please check the below code snippet to avoid this. This will help us to check whether user end is manipulating something in the URL, if so then we cannot create a new GUID the catch block will be executed and generic error message will display. the same logic can be applied for any data type.
try
{
string Key = Request.QueryString["e"];
Guid ErrorGUID = new Guid(Key);
lblError.Text = string.Format("Please provide the following error code {0}.", ErrorGUID.ToString();
}
catch ()
{
//handle exceptions accordingy
}

SSIS Error code DTS_E_OLEDBError 0X8004005 ...

SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred.
sometimes we get as "Login failed for user" or "User might not have permission to do the activity".

I was getting this error for quite sometime when I execute the package using "Execute Package utility" I tried looking this msdn site for , but that does not help. Even though i changed the settings and try to execute it is prompting the same error.

Reason: At last i got the solution from this msdn blog (which also contains solution for different kinds of SSIS errors). While setting the DB connection, I check the save password check box to avoid entering multiple times. That is reason for it. Normally if we have to set the password permanently for the connection then we are suppose to set the password for package also. And also the package encryption level must be set to "EncryptSensitiveWithPassword" or "EncryptAllWithPassword". This both go in pair. If you set the encryption level and not setting the package password it will throw an error.

Solution:
1. While setting the connection details, we should not check the Save Password option and package encryption can be default. As a best practice, we can set the package configurations through config file.

Reference for package configurations in msdn site

Prerequisite:
1. Make sure you have the latest version of BIDS.
2. Update the SQL server with all available service packs.
3. While setting the connection string using config file, please make sure you are setting the connection provider also.

Migration from VS 2005 to VS 2008

I recently got a opportunity to migrate a VS2005 project to VS2008. I was reading all the pros and cons of migration from the different sites. The simple thing to migrate the solution is open the 2005 solution from the VS 2008 IDE, it opens a wizard and take you through each step and convert the whole project. After migration it creates a Migration report which tell the status of migration. 99% of the project gets migrated in one click. Some of the solution will have a problem. If you get a chance to compare the sln file before and after migration the only change you can find is mentioned below:

VS2005 sln file: Microsoft Visual Studio Solution File, Format Version 9.00
VS2008 sln file: Microsoft Visual Studio Solution File, Format Version 10.00

The project files (*.vbproj or *.csproj) will not be affected or modified during the migration.

One more way to do this is create a Blank solution in VS2008 and start adding vs2005 projects to it. If we have multiple projects, then it will be little tedious to add each and every project.

We have a constraint here. If you solution has SSRS or SSIS projects associated to that then it will not get migrated on its own. We need to migrate it separately. While doing this we should make sure the SQL versions is also upgrated to SQL Server 2008. It is simple in development machine, but while deploying if the environment does not support then we will be in trouble. But for Window and Web projects, we will not find any problem until we change the framework. VS2008 supports multi-targeting, I mean it supports to compile and run your project in different framework starting from Net Framework 2.0.

One more funniest thing is we can have two sln files for same project to work in two different VS versions. This will not affect the project until you do not change the target framework. This is not a best practice, but helps in critical situations.

I referred the below link to know more information before migrating the project. This is really worth reading even for knowledge sake.

Business Intelligence Development Studio 2005 (BIDS)


I recently want to update visual studio 2005 with service pack. The moment i installed in my machine, my studio started behaving very funny. IDE is having repeated menu items with repeated sub menu. I tried repair the studio with reinstalling the service pack and the problem is still more worse. Menus got doubled than before. I tried setting the IDE using Import and Export setting and that does not help. All I need is BIDS and not full version of VS2005 as my projects are migrated to higher versions. So I uninstall the VS2005 from my machine. I uninstall Visual Studio Premier Partner Edition also (by mistake), Please do not uninstall that as it is required for BIDS.

I have SQL Server 2005 database services installed already in my machine, and I downloaded the latest version of service pack for Microsoft SQL Server 2005 (Service Pack 4 RTM) and installed in my machine. During the installation wizard there is a option to select the tool which you want to upgrade, select all and proceed.

Installation went well with one fix failed, and it opened the provisioning tool to set the access for my SQL server database engine. Once the installation is done, IDE started configuring on its own and it ready. I got this information in one of the site mentioned below. But still I want to post the full history to understand the history behind this.

Info I found in that site:
You should make sure that Visual Studio is still installed. If you didn’t previously have VS installed, the BI Dev Studio installation will install a VS shell called Visual Studio Premier Partner Edition. Look in Add or Remove Programs for an entry like this. If you don’t find any entry for Visual Studio go to the location for SQL Server setup and run .\Tools\Setup\vs_setup.exe. This will install the VS Shell. After this is installed repair the BI Studio installation by running the following from the command line from the .\Tools directory: start /wait setup.exe /qb REINSTALL=SQL_WarehouseDevWorkbench REINSTALLMODE=OMUS

SSRS sub report not visible while rendering

We need to verify the Hidden property in the visibility section and make sure it is said to false (hidden=false). Remove the expression and try hardcoded values like true or false. Make sure all the parameters defined in the sub report are properly associated in the main report. One of the reasons is if the sub report is having dataset associated to it and the dataset is not returning a single record will be a problem. Otherwise the record may contains all null values.


 

SQL SERVER 2005 Uninstalation issue ( Error code : 2147024893)

Error : The setup failed to read IIsMimeMap table. The error code is -2147024893.

Description : we get this error when we try to uninstall the reporting services individually or SQL server 2005 as a whole package. the reason for this selecting the mixed mode for authentication while installation. even the microsoft does not have the solution for this.

Workaround for this is ...
1. Uninstall the IIS
2. Uninstall the SQL server 2005 or reporting services.

Happy Coding :)