X-AspNet-Version in headers - why? and how to remove them

Monday, June 9th, 2008

Sometimes .NET really winds me up. Why do they by default put things that could potentially give a hacker some information. I know security by obscurity is not the best way forward but why leave your front door open!

Anywho - it is really easy to get rid of:

Find or add the element <httpRuntime> in your web.config and add the attribute enableVersionHeader=”false”.

The msd documentation can be found here: http://msdn.microsoft.com/en-us/library/e1f13641.aspx

Creating a scheduled job using .NET - bit like a cron job

Sunday, May 25th, 2008

Will review these solutions:

http://www.codeproject.com/KB/dotnet/ABTransClockArticle.aspx

http://www.codeproject.com/KB/cs/tsnewlib.aspx

AppSettings ASP.NET & MasterPages

Wednesday, May 21st, 2008

You don’t always have to use the old:

ConfigurationManager.AppSettings["whatever"]

In a master page you can also use a bit of short hand:

<%$ AppSettings:whatever%>

Saves some typing a suppose…

Visual Studio 2008 Colour schemes

Tuesday, May 20th, 2008

The standard white background is a little boring and if you are looking at it all day it gets a bit bright so I thought I would have a change.

I found a few that I liked from here and here

I took one and altered it to my liking.

ID mangling in ASP.NET MasterPages

Monday, May 19th, 2008

This is fine if you just let .NET generate your client side script - but what if I want to write my own? What options do I have?

  1. Alter all your ID’s in your script as they will always be mangled the same! - I would rather not thanks..
  2. Change the ID’s in your script at runtime - not great but better
  3. Got any better ideas?

VB I know but you still get the idea:

Dim script As String = “[Label1ID].innerHTML = ‘boo!’;”
Dim scriptKey As String = “SayBoo”
Dim addScriptTags As Boolean = True

Protected Sub Page_Load(ByVal sender As Object, _
ByVal e As EventArgs)

script = script.Replace(“[Label1ID]“, Label1.ClientID)

ClientScript.RegisterStartupScript( _
Me.GetType(), scriptKey, script, addScriptTags _
)

End Sub

Thanks to: http://www.odetocode.com/articles/450.aspx

Meta Tags in a .NET Master Page

Monday, May 19th, 2008

At first I thought the best approach would be to use a content place holder but then I thought no this is .NET and the framework should have a way to let me do this a little more elegantly (I do like my code to be elegant)

So the way I plumped to do this was to use the HtlmHead object. The MasterPage exposes the Head element and you can add attributes like so:

HtmlHead head = (System.Web.UI.HtmlControls.HtmlHead)Header;
HtmlMeta keywords = new HtmlMeta();
keywords.Attributes.Add(”name”, “keywords”);
keywords.Attributes.Add(”content”, Product.Keywords);
head.Controls.Add(keywords);

Dead easy really. Whilst Googling I did find some other useful info on MasterPages - fixing those mangled ID’s in master pages etc!

Simpler:

HtmlMeta tag = new HtmlMeta();
tag.Name = "description";
tag.Content = "My description for this page";
            Header.Controls.Add(tag);

AJAX and .NET - use the UpdatePanel!

Wednesday, May 14th, 2008

http://asp.net/ajax/documentation/live/overview/updatepaneloverview.aspx

Output caching profiles ASP.NET 2.0

Saturday, May 10th, 2008

Dead easy to do:

Add the profiles to the web.config

<?xml version=”1.0″?>
<configuration>
<system.web>
<caching>
<outputCacheSettings>
<outputCacheProfiles>
<add name=”StaticPageCacheProfile” duration=”14400″ />
<add name=”UserControlCacheProfile” duration=”60″ />
</outputCacheProfiles>
</outputCacheSettings>
</caching>
</system.web>
</configuration>

Then just add that to the page declaration:

<%@ OutputCache CacheProfile=”StaticPageCacheProfile” VaryByParam=”none” %>

It would also be a good idea to separate out the cache profiles to a separate config file and then use MSBuild to pull the correct ones in at deploy time. I hate forgetting to change the profile when you are working on the site on DEV and it doesn’t change or a designer comes over telling you nothing has changed!

Setting the locale for currency etc .NET

Friday, March 21st, 2008

http://msdn2.microsoft.com/en-us/library/bz9tc508(VS.80).aspx

MS-Build in visual web developer 2008

Sunday, March 16th, 2008

http://blogs.msdn.com/jamesche/archive/2007/09/27/automating-aspnet-compiler-in-visual-web-developer.aspx