Wednesday, 30 January 2008

Where are my IIS Logs?

Although you may have bucket loads of logging taking place in your web applications/sites, you may still feel the need to make use of the IIS logs. Use the following steps to track down these hidden away log files:

  1. Open Internet Information Services (IIS)
  2. Right-click the desired web site and select properties
  3. On the Web Site tab, at the bottom is the Active Log Format; select the properties button next to it
  4. You'll now have a box that contains the log file directory and the log file name. Together they make the full log path.

In this window you can also change useful settings like what request/response details are recorded in the logs. Some useful options not selected by dfault are bytes sent, bytes received and referrer (useful for tracking 404s in certain cases).

Extracting useful info from these log files is another blog post all together ;)

Monday, 28 January 2008

User is not associated with a trusted SQL Server connection

Login failed for user 'username'. The user is not associated with a trusted SQL Server connection.

This error had me scratching my head today for around 30 mins (mainly because I rarely setup SQL Server instances from scratch), and took me just 30 secs to fix.

Basically the SQL server instance you are conecting to has been configured to operate in Windows Authentication Mode and doesn't allow the use of SQL accounts. So change the Authentication Mode of the SQL server from Windows Authentication Mode to Mixed Mode (Windows Authentication and SQL Server Authentication). To do this right click your SQL Server instance in Enterprise Manager/Management Studio, select security and you should see the option in there. Hope you didn't waste as much time as I did on this :)

ASP.Net AJAX Not Working (Full page postback)

The conversion process from VS 2003 to VS 2005 for web projects may result in strange behaviour when adding new client-side JavaScript to the project. For me this was evident when using ASP.Net AJAX UpdatePanel controls, which resulted in a page performing a full-page postback instead of a partial page postback of the desired AJAX page elements.

ASP.Net 1 and 1.1 did not emit XHTML compliant markup from countless server controls. ASP.Net 2 changed this and defaults to emitting XHTML compliant markup from all controls. Beta testing of ASP.Net 2 showed Microsoft that this could affect certain web apps and to prevent this a xhtmlConformance setting was introduced and added in the conversion to the config file:

<system.web>
   <xhtmlConformance mode="Legacy" />
</system.web>

If you are having ASP.Net AJAX issues I recommend removing the <xhtmlConformance> section from your web.config file or perhaps set it to Transitional or Strict.

The good new about this is it will result in your HTML from your server controls to be well formed (i.e. all tags are closed for all elements). Important in ASP.Net AJAX implementations because AJAX dynamically replaces the contents of HTML elements on your web page. If the tags aren't well formed, the AJAX JavaScript can get it's knickers in a twist with regards to the containers it should be updating, resulting in big problems.

Tip

It's also worth checking the framework's web.config file for the setting if you think this is affecting you and the setting isn't in your app's web.config

Tuesday, 22 January 2008

Browser CSS Differences (IE6 IE7 Firefox)

Typically the 3 major browsers used are Firefox, IE6 and IE7. Perhaps you thought they would behave the behave the same when rendering CSS in the browser window? If only life were that simple.

Although Firefox and IE7 and more similar than ever in rendering CSS, IE6 has always had a mind of its own, adding padding and spacing amongst other things in random locations. However, there is a simple way to cater specifically for the major browsers. IE6 recognises underscore lines, but IE7 does not. IE6 and IE7 recognise period lines. For example...

#header
{
margin-top: 8px;
.margin-top: 10px;
_margin-top: 4px;
}

Firefox, and every other non-IE browser, will only see and use the 8px, IE6 will see the 10px line, but then the 4px line will stomp on it, and only IE7 will see the 10px line. You can now support all major browsers without having to write a serverside script, clientside script or even a horrible CSS expression :)

Regular Expression for a GUID

Just a quick post, if you ever need a regular expression to match a guid, for example - in a URL, then look no further :)

([0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12})

Thursday, 17 January 2008

Getting Started with Profiles In ASP.Net 2

Profiles In ASP.Net 2 uses the same provider-based structure used by ASP.NET membership and role management amongst other features. ASP.NET includes a profile provider that stores data using Microsoft SQL Server. The default ASP.NET machine.config contains a default SqlProfileProvider instance named AspNetSqlProfileProvider that connects to SQL Server on the local machine. By default, the ASP.NET profile feature uses this provider. You can alternativly specify another in the web app's web.config (step 3). The simple steps below should get you started using Profiles in your .Net 2 web apps:

  1. Create the database using the ASP.Net Profile Providers MSDN article.
  2. Create your profile section in your web app's web.config file:
  3. Specify your custom SQL database if not using the default from the machine.config but updating your web.config:
  4. Start using your Profiles for authenticated users:

Profiles in .Net generally have alot more to them then what I've detailed above, the links below should help you get started:

Wednesday, 16 January 2008

JavaScript Syntax Highlighter for C# SQL XML VB and more

To bring your code to life on your blogs/web sites there is a great syntax highlighter written in JavaScript simply called Syntax Highlighter and best of all ...it's free! Supported languages/markup include C, C++, C#, CSS, Delphi, Java, javaScript, PHP, Python, Ruby, SQL, VB, XML, HTML - see the C# example below:

To get it running on your pages; download the files from the Syntax Highlighter site to your server, on your web page just pull in the CSS file, the required JS files (according to your language choices) and set some JS values on page load:

<link href='/css/SyntaxHighlighter.css' rel='stylesheet' type='text/css'/>

<script type='text/javascript' src='/js/shCore.js'/>
<script type='text/javascript' src='/js/shBrushCSharp.js'/>
<script type='text/javascript' src='/js/shBrushXml.js'/>
<script type='text/javascript' src='/js/shBrushJScript.js' />

<script type='text/javascript'>
window.onload = function () {
    dp.SyntaxHighlighter.ClipboardSwf = '/flash/clipboard.swf';
    dp.SyntaxHighlighter.HighlightAll('code');
}
</script>

Once this is set up you can just place your code on the page surrounded by pre/textarea tags. Then specify a class according to the language alias you wish to use (aliases are listed on the Syntax Highlighter site).

<textarea name="code" class="c#" cols="50" rows="10">
... some code/markup here ...
</textarea>

Monday, 14 January 2008

IHttpHandler IsReusable Property

There isn't much clear info regarding this property on the net. It can be better in terms of performance when the property is set to true, but can cause some headaches if you have set it to true in the wrong scenario.

public bool IsReusable
{
   get
   {
      return false;
   }
}

The property is used to indicate if a single intantiation of your IHttpHandler implementation can be used to process multiple concurrent requests. Each client request is considered to be a worker thread on the serverside when being processed through the ASP.NET pipeline. So, if we set IsReusable = true, we need to make sure that our ProcessRequest method is threadsafe. The ProcessRequest should not rely on any state that could be modified by other concurrent request threads. Important when your IHttpHandler implementation does expensive initialisations, otherwise it probabaly doesn't really matter if you return true or false (since simple object allocation is fairly inexpensive in .NET). N.B. Pages are never pooled.

Monday, 7 January 2008

System.Web.HttpException: Maximum request length exceeded

The HttpRuntimeSection.MaxRequestLength is a property new to the .Net 2 framework, which is used to control the maximum request size in kilobytes for a web app. The default size is 4096 KB (4 MB), and the property is useful for preventing DOS (denial of service) attacks caused by site users posting large files to the server.

If you are uploading large files to a web app you may find the property retricting and you'll need to override the default value of this property to something you can work with. You can do this by modifying your web.config or machine.config, although I suggest setting a new value for this property in web.configs (on a per web app basis) as it would be unlikely you need all the web apps on a server to have a large upload limit and this may open up your web server to increased risk of DOS attacks.

<system.web>
    <httpRuntime maxRequestLength="XXXX" />
</system.web>

MSDN info on modifying your HttpRuntimeSection.MaxRequestLength property.