Saturday, December 18, 2010

Configsource

A collegua of me sent a while ago a link about ConfigSource. I think this is an easy way for dividing the web.config is some logical parts. So I am goiing to use this in my (private) projects. Unfortunately the external file must be in a relative physical path to the application because of security reasons.


Update:The attribute configSource works only for a complete section and NOT for a single ConfigurationElement.

Monday, December 6, 2010

ToOADate

For a couple of my hobby web sites I use an Access database. When I upgrade these website to ASP.NET 4.0 Framework I have had also to update some calls to the database for the DateTime columns, I have to use the ToOADate() method.

Wednesday, November 17, 2010

Repeater: Custom ItemTemplate

When you want to create a custom item template in a repeater you have to readthis article. In this article the css-class and the html depends of the content of the data collection. So you want a different ItemTemplate for another row.

Web.config customErrors element

In de web.config of a (web) application it is possible te configure the customErrors element. Mostly for development I want to see the details of the errors so I can fix these quickly. But when the application runs for end-users I want to be informed about these errors and the users sees a friendly message "there is something wrong, this is registrerd".

Monday, November 1, 2010

ildasm.exe

In the command prompt of Visual Studio it is possible to call the windows tool
ildasm.exe. With this tool the assembly manifest is readable and so the related assemblies can be retrieved.

Monday, October 18, 2010

Public token key

With the 'sn.exe' tool of Visual Studio it is possible to retrieve the public token key. But watch for the casing!!

Use the command: sn.exe -Tp "FilePath to assembly"

Tuesday, October 12, 2010

Fiddler and localhost

Working with Fiddler for seeing the details of the Http request of a website is usefull for optimizing the performance of a website. Check if there are unneeded requests or if there are many requests which triggers a 404.

A tip when working with localhost you must http://localhost.:1519/default.aspx instead of
http://localhost:1519/default.aspx. So add a point behind the hostname.

IEnumerable Empty

When creating an IEnumerables, I mostly returned a null value when there are no values for the collection. But it is in some situations better to return an empty collection. This can be done with the Enumerable.Empty method.

Wednesday, May 19, 2010

How to take ScreenShot in C#

From this article I have copied the code below for taking a screenshot. I have not yet tested this code, because I do not reminder where I need this... when I do I will update this post:)

here is the code in C# for screenshot.

int screenWidth = Screen.GetBounds(new Point(0, 0)).Width;
int screenHeight = Screen.GetBounds(new Point(0, 0)).Height;
Bitmap bmpScreenShot = new Bitmap(screenWidth, screenHeight);
Graphics gfx = Graphics.FromImage((Image)bmpScreenShot);
gfx.CopyFromScreen(0, 0, 0, 0, new Size(screenWidth, screenHeight));
bmpScreenShot.Save("test.jpg", ImageFormat.Jpeg);

Friday, April 30, 2010

.NET Framework 4

Since the beginning of this month is .NET Framework 4 released. When migrating to a newer version of the framework, there are always some issues. These issues are listed on the MSDN site. Hope it helps!

Update: Some changes from another view

Thursday, March 25, 2010

Embedded Resources

When you work with embedded resource, you can use the following code to get a list of all the embedded resources in de current assembly:

foreach (string s in this.GetType().Assembly.GetManifestResourceNames())
System.Diagnostics.Debug.WriteLine(s);


More info on How to use assemlby embedded resources

Friday, March 12, 2010

Check your web.config

Check your web.config on these common mistakes which occurs in the web.configs.

IIS 7 and IIS 7.5

The IIS version for Windows Server 2008 (Vista) is IIS7 and the IIS version for Windows Server 2008 R2 (Windows 7) is IIS 7.5. read more information about specific details. At the moment it is not clear for me what the difference are for configuring a web application in IIS 7 and IIS7.5, specially for the web.config. When I know more about this, I will blog this....

Browser capabilities

Test your browser capabilities on this site. When you use the Developer Toolbar for disabling Javascript or CSS support you can see the results on this page. Also useful for crossbrowsing web development.

Monday, March 8, 2010

Name Mangling

Name Mangling is a definition which is used inside a programming language. For example: A compiler uses this, for unique identification for private fields by prefixing the private fields with the class name.

Monday, February 8, 2010

Taking Shapshots in ASP.NET

On the blog of ENES TAYLAN I have found an article about Taking Shapshots in ASP.NET. It is a nice feature, but it must be provided as webservice, in the example on this page it can only be used a stand-alone.

Which exceptions are there in .NET?

On the blog of Mikesdotnetting there is a article which summaries some exceptions from the .NET Framework. So these can be used.

Monday, February 1, 2010

How to get an indexed item of an IEnumerable object (Linq)

How to get an indexed item of an IEnumerable object (Linq), this is a question which I often have had when I start using IEnumerable. But it is possible with the ElementAt() extension method!.

Friday, January 22, 2010

Get the name of the method

Sometimes it is easy to print the methodname of the current method. This can be typed manually, but with use of Reflection this can be retrieved with the following simple command:

System.Reflection.MethodBase.GetCurrentMethod().Name

Monday, January 11, 2010

Saturday, January 9, 2010

Reflector

Reflector is a tool for disassembly a dll. So you can see the source code and you can analyse if the assembly works correctly.

Link dump

Loading Message with Ajax
http://weblogs.asp.net/aghausman/archive/2009/07/20/show-loading-message-in-asp-net-ajax.aspx

Resolve urls with Javascript
http://weblogs.asp.net/joelvarty/archive/2009/07/17/resolveurl-in-javascript.aspx

Logging guidelines
http://www.bugfree.dk/blog/2009/07/22/basic-logging-guidelines/

Enterprise Library Logging

For logging exception the Enterprise Library an usefull tool.

.NET Validators

When using 'Validators' you must use the property "IsValid" and you must use the method "Validate".
For a CustomValidator you must implement the 'ServerValidate' event.
Also the property 'ClientValidationFunction' must be set to organize the Client side validatie.

source: validator
arguments.value: the control which must be validated
arguments.isvalid: true if the value is valid otherwise false.
- http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.customvalidator.aspx
- http://www.codeproject.com/KB/validation/MultiDependValidator.aspx

Do not use underscores in DNS computer names

The support of Internet Explorer with underscore is not the same as for browsers like firefox and chrome.

Take the following address: http://pc02_test.domain.com/webapp

When you now want to store some information in the cookie, this goes wrong. So the advise is do not use underscores!

More information:

- http://social.msdn.microsoft.com/Forums/en-US/iewebdevelopment/thread/8e876e9e-b223-4f84-a5d1-1eda2c2bbdf4
- http://www.enhanceie.com/ie/bugs.asp (IE005)
- http://support.microsoft.com/kb/909264

Environmental overrides with Enterprise Library

For the most application there are several environments available. Each environment has his own configuration (like connection string, files and so on).

With Enterprise Library you can create environments and override some properties of the web.config. See for more information: Environmental overrides.