Blog Home  Home Feed your aggregator (RSS 2.0)  
U R MY.Net
My Tips, Tricks and References
 
 Tuesday, January 03, 2012

When I upgraded to ASP.NET 4.0, runtime errors suddenly became very slow. There was a consistent two-minute delay before my custom error page would appear. The rest of the website was lightning fast, so it was not related to compilation. I finally decided to tackle this problem, so I started copying blocks of code into a new, blank custom error page. The delay was not present until I copied this line of code:

Response.StatusCode = 500

I had been searching the web for terms like "asp.net error page very slow" with no success. One quick search on "asp.net statuscode slow" finally returned some helpful results:

http://stackoverflow.com/questions/3288797/page-not-rendered-when-sending-statuscode-500-to-the-client

http://msdn.microsoft.com/en-us/library/system.web.httpresponse.tryskipiiscustomerrors.aspx

http://www.west-wind.com/weblog/posts/2009/Apr/29/IIS-7-Error-Pages-taking-over-500-Errors

All I had to do was drop in one line of code where I set the status code.

Response.TrySkipIisCustomErrors = True

The delay is gone now, but I still have no idea what's going on inside the black box.

Tuesday, January 03, 2012 12:39:45 PM (Pacific Standard Time, UTC-08:00)  #    Comments [0]    |   | 
 Wednesday, November 30, 2011
I just came across this article that talks about changes to Google's search results algorithm.
http://www.seomoz.org/blog/beat-google-panda

The five “penalties” listed are:
1. Heavy Template Footprint
2. Empty Content
3. Overlapping and Redundant Articles
4. High Ad Ratio
5. Affiliate Links and Auto Generated Content

But the two significant points from this review are 1) how usable is the site from a human perspective and (more importantly) 2) what is the bounce rate? The bounce rate I'm finding is very important. It looks like search engines are monitoring how long a person is on a site. If the person hits the back button right away the search engine will catch this and change the ranking of this site in the search results.
Wednesday, November 30, 2011 11:38:42 AM (Pacific Standard Time, UTC-08:00)  #    Comments [0]    | 
 Friday, November 04, 2011

Writing a Business-Oriented JavaScript Web Application:
http://msdn.microsoft.com/en-us/magazine/hh475811.aspx

Friday, November 04, 2011 8:24:41 AM (Pacific Standard Time, UTC-08:00)  #    Comments [0]    |   | 
 Friday, September 30, 2011

Everyone uses Google Analytics. Did you know they now offer a "premuim" service? For the low, low price of $150,000 you can get Extra processing power, Advanced analysis, Service and support, and Guarantees.

More details here.

Friday, September 30, 2011 8:38:19 AM (Pacific Standard Time, UTC-08:00)  #    Comments [0]    | 
 Thursday, September 01, 2011

I'm a Microsoft fan. I'm also considering the convenience of a tablet. Should I get an iPad? Sorry, I just can’t bring myself to bite the apple. What shall I do? Well, I can hope when Microsoft gets into the tablet game they will do it cost efficiently and effectively.

Thursday, September 01, 2011 11:21:22 AM (Pacific Standard Time, UTC-08:00)  #    Comments [0]    | 
 Thursday, August 25, 2011

When adding the Facebook Like button to a page, be sure to add the image Property meta tag:

<meta property=”og:image” content=”<full path to image>”/>

Here are other tag that can be added:

<meta property=”og:title” content=”<Title of the page>”/>

<meta property=”og:site_name” content=”<Title of the site>”/>

Here is the Facebook Like button generator:

http://developers.facebook.com/docs/reference/plugins/like/
Thursday, August 25, 2011 8:15:33 AM (Pacific Standard Time, UTC-08:00)  #    Comments [0]    | 
 Friday, August 19, 2011

IIS Crypto is a free tool that gives administrators the ability to enable or disable protocols, ciphers, hashes and key exchange algorithms on Windows Server 2003 and 2008. It also lets you re-order SSL cipher suites offered by IIS.

https://www.nartac.com/Products/IISCrypto/Default.aspx

Friday, August 19, 2011 2:32:12 PM (Pacific Standard Time, UTC-08:00)  #    Comments [0]    |  |   | 
 Wednesday, August 03, 2011
Test your certificate chain: SSL Test
Wednesday, August 03, 2011 11:10:04 AM (Pacific Standard Time, UTC-08:00)  #    Comments [0]    |  |   | 

Controls inside an ASP.NET UpdatePanel cannot be bound to jQuery events after a partial postback. Here are some tips using pageLoad():

Wednesday, August 03, 2011 10:54:53 AM (Pacific Standard Time, UTC-08:00)  #    Comments [0]    |  |  |   | 
 Tuesday, August 02, 2011
Tuesday, August 02, 2011 11:28:17 AM (Pacific Standard Time, UTC-08:00)  #    Comments [0]    |   | 
 Saturday, March 12, 2011

There have been many articles and forums addressing the fact that the MaxLength property of the ASP.NET TextBox does not work when you set TextMode to MultiLine. The majority of these solutions use the KeyPress and OnBlur events. This brings with it lots of JavaScript and a host of browser issues. I was impressed by the RegularExpressionValidator options because they can tie in to the AJAX ValidatorCalloutExtender. I also like the server-side validation that you get with the native validation controls.

The solution I settled on is a combination of all the above. I use an ASP.NET RegularExpressionValidator on the MultiLine TextBox. The code looks like this:

<asp:TextBox runat="server" ID="txtDescription" TextMode="MultiLine" Rows="5" Width="300" />
<
asp:RegularExpressionValidator runat="server" ID="revtxtDescription" ControlToValidate="txtDescription" ErrorMessage="Exceeds 500 character maximum." ValidationExpression="^[\s\S]{0,500}$" Display="None" />
<
ajax:ValidatorCalloutExtender ID="vcerevtxtDescription" runat="server" TargetControlID="revtxtDescription" />

Good so far, but to quote Mark Hildreth:

"I agree that that works for preventing users from posting too much text, however it does't prevent them from typing more than 500 characters into the box. The validators only perform their validation in the onchange event which is not triggered on every key stroke. Imagine your dismay if you spent 10 minutes typing into a textbox, only to have the form say you have exceeded the 500 character limit?"

The JavaScript below will call this RegularExpressionValidator every second. I find that it does not noticeably slow down the form.

<script type="text/javascript">

    $(document).ready(function () {
        setInterval("validateDescription();", 1000);
    });

    function validateDescription() {
        var myValidator = document.getElementById("<%= revtxtDescription.ClientID %>");
        ValidatorValidate(myValidator);
    }

</script>

Now as the user is typing, they will be warned within one second of exceeding 500 characters. If they paste into the textbox, it will alert them too.

Saturday, March 12, 2011 1:08:42 PM (Pacific Standard Time, UTC-08:00)  #    Comments [0]    |  |  |   | 
 Friday, February 18, 2011

Sometimes I require unique values in a column that allows nulls.

CREATE UNIQUE NONCLUSTERED INDEX IndexName ON dbo.TableName(ColumnName) WHERE ColumnName IS NOT NULL

http://connect.microsoft.com


Update: SQL Server Management Studio has this functionality built into the Index Properties dialog.

([ColumnName] IS NOT NULL)

http://stackoverflow.com

Friday, February 18, 2011 10:57:30 AM (Pacific Standard Time, UTC-08:00)  #    Comments [1]    | 
 Thursday, January 27, 2011
Thursday, January 27, 2011 4:17:59 PM (Pacific Standard Time, UTC-08:00)  #    Comments [0]    | 
 Wednesday, January 26, 2011

As far as I can tell, it is trivial to enable multiple simultaneous remote desktop sessions for Windows Server 2008.

  • Open gpedit.msc
  • Navigate to Computer Configuration -> Administrative Templates -> Windows Components -> Remote Desktop Services -> Remote Desktop Session Host -> Connections
  • Double-click "Restrict Remote Desktop Services users to a single Remote Desktop Services session
  • Check "Disabled" and apply.

There is one caveat, however. It seems to leave a Console session active at all times. You can log off the Console session via Task Manager. If you connect to it (by right-clicking it in task manager) it doesn't seem to be doing anything.

Wednesday, January 26, 2011 4:52:36 PM (Pacific Standard Time, UTC-08:00)  #    Comments [0]    |   | 
 Wednesday, January 19, 2011

Expanding on the post "Entity Framework Filter Child Entity", I finally figured out how to get a GridView to show the count of child records. Unfortunately I am returning the whole set of entities and doing a Count on them. It's not a problem in this case. I'm just happy it works.

Dim query = (From x In db.OrderChecklistItems Where x.Enabled = True Order By x.Enabled Descending, x.ItemText Select OCI = x, _
            
OD = From y In x.OrderDocuments Where y.OrderID = OrderID, _
            
CS = From z In x.OrderChecklistSelections)
 
Dim customers = From item In query.ToList Select item.OCI
 
GridView1.DataSource = customers
GridView1.DataBind()

Then in the GridView:

Eval("OrderChecklistSelections.Count")
Wednesday, January 19, 2011 3:48:55 AM (Pacific Standard Time, UTC-08:00)  #    Comments [0]    | 

I was looking for a way to filter child entities with eager loading. I ran into this useful blog post by Beth Massi on the subject.

Here is the code I ended up using. It doesn't work with server-side paging, but I didn't need it in this case.

Dim query = (From x In db.OrderChecklistItems Where x.Enabled = True Select OCI = x, _
             
OD = From y In x.OrderDocuments Where y.OrderID = OrderID)

Dim
customers = From item In query.ToList Select item.OCI

GridView1.DataSource = customers

Wednesday, January 19, 2011 2:46:54 AM (Pacific Standard Time, UTC-08:00)  #    Comments [0]    |   | 
 Tuesday, January 18, 2011

I found it tricky to get actual entities in the GridView RowDataBound event.

Per Diego Vega's post here, this may only happen because I am using the EntitySetName property of the EntityDataSource.

    Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim descriptor As ComponentModel.ICustomTypeDescriptor = e.Row.DataItem
 
            If descriptor IsNot Nothing Then
                Dim prop = descriptor.GetProperties().Cast(Of ComponentModel.PropertyDescriptor)().First()
 
               
Dim Order As Order = DirectCast(descriptor.GetPropertyOwner(prop), Order)
 
               
Response.Write("Order Number:" & Order.OrderNumber)
           
End If
       
End If
   
End Sub

Tuesday, January 18, 2011 11:35:23 PM (Pacific Standard Time, UTC-08:00)  #    Comments [0]    |   | 
 Wednesday, January 05, 2011

In a GridView I have a column of checkboxes and a column of textboxes. I wanted to modify the value of the textbox when the checkbox is checked. jQuery is the perfect fit for this. Here is the code I used:

$(function () {
    var $inp = $('input:checkbox');
    $inp.bind('click', function () {
        var textbox = $(":input:text:eq(" + $inp.index(this) + ")");

        if (this.checked == true) {
           
textbox.val('123ABC');
            textbox.attr('disabled', 'disabled');
        } else {
            textbox.attr('disabled', '');
        }
    });
});

This post uses ideas from Suprotim Agarwal.

Wednesday, January 05, 2011 11:01:56 AM (Pacific Standard Time, UTC-08:00)  #    Comments [0]    |  |   | 
 Friday, December 31, 2010

I ran across this post on Stack Overflow. Here is the code I ended up using:

Dim count = (From x In db.Orders Where x.OrderID = orderID From y In x.OrderDetails Select y).Count

Friday, December 31, 2010 1:53:21 AM (Pacific Standard Time, UTC-08:00)  #    Comments [0]    |  |   | 

SQL Server Profiler requires you to have ALTER TRACE permission. There are two ways to grant that permission.

Properties: Object Explorer -> Security -> Logins -> your_login -> Securables -> Search button -> "The server" radio button -> "Grant" checkbox on "Alter Trace"

SQL: GRANT ALTER TRACE TO myuser

Friday, December 31, 2010 1:44:53 AM (Pacific Standard Time, UTC-08:00)  #    Comments [0]    | 
 Thursday, December 16, 2010

To make Silverlight redirect a user to an ASPX or HTML page in your current website, use the following code:

System.Windows.Browser.HtmlPage.Window.Navigate(New Uri("/contact-us.aspx", UriKind.Relative))

To redirect anywhere, use:

System.Windows.Browser.HtmlPage.Window.Navigate(New Uri(http://www.bing.com))

If you are trying to redirect to another XAML page, there are lots of resources elsewhere to help you.

Thursday, December 16, 2010 2:40:28 PM (Pacific Standard Time, UTC-08:00)  #    Comments [0]    |   | 
 Friday, December 10, 2010

To save a password hash to an XML file, you can call this function:

FormsAuthentication.HashPasswordForStoringInConfigFile(txtPassword.Text & "|" & txtUsername.Text, "SHA1")

You can see my attempt at a password salt by simply apppending the Username.

Friday, December 10, 2010 5:34:44 PM (Pacific Standard Time, UTC-08:00)  #    Comments [0]    | 
 Saturday, October 30, 2010

I don't have any fancy program to generate an icon. Since I always forget how to do this, here are simple instructions:

Open the logo in Photoshop and flatten it to one layer on a transparent background. Duplicate it and resize to 16x16 pixels. Open a new instance of Visual Studio and click New File. Select Icon and it will open a pane with two versions. The first version is 16x16, and will appear in browsers. There is also a 32x32 version, which I always do just in case someone adds a link to their desktop.

Set up the image type in Visual Studio. The default image type is 4 bit, and you want 24 bit. Press Insert on your keyboard and select "16x16, 24 bit" then delete the 4 bit image type.

Go to Photoshop and copy the entire canvas to the clipboard. Return to Visual Studio and CTRL+A, Delete, CTRL+V. Switch to the 32px version and the thumbnail for the 16px version should update.

Back in Photoshop, close the 16px version and resize the original to 32px. Copy it into Visual Studio the same way as above. Save as favicon.ico, and upload it.

The HTML code I use is as follows:

<link rel="SHORTCUT ICON" type="image/x-icon" href="/favicon.ico" />

Saturday, October 30, 2010 1:32:21 PM (Pacific Standard Time, UTC-08:00)  #    Comments [0]    | 
 Saturday, October 23, 2010

I expected to type \n into the ConfirmText property of the AJAX Control Toolkit's ConfirmButtonExtender and get a new line.

This doesn't work, but you can use this character code: &#10;

Specifically, amersand pound 10 semicolon.

Saturday, October 23, 2010 11:07:27 AM (Pacific Standard Time, UTC-08:00)  #    Comments [0]    |  |  |   | 

Sometimes I want to show the e.Row.RowIndex of a GridViewRow in the markup of the page. I don't want to hook into the RowDataBound method just to display a simple number. The answer varies for GridViews and Repeaters. Click here for the complete rundown.

GridView:

<asp:Literal runat="server" Text='<%# Container.DataItemIndex + 1 %>' />

Repeater:

<asp:Literal runat="server" Text='<%# Container.ItemIndex + 1 %>' />
Saturday, October 23, 2010 11:04:13 AM (Pacific Standard Time, UTC-08:00)  #    Comments [0]    |  |   | 
 Friday, May 28, 2010
This guide is a must use for sending HTML email newsletters: http://www.campaignmonitor.com/css/

Friday, May 28, 2010 11:16:39 AM (Pacific Standard Time, UTC-08:00)  #    Comments [0]    |   | 
 Monday, May 24, 2010


Data Access Practices Using Microsoft .Net: A Nerdly Comparison

In this article a comparison of these options:
- Connected Data Access with ADO.NET
- Disconnected Data Access with ADO.NET and Typed DataSets
- Basic Object Relation Mapping with LINQ to SQL
- Object Relational Mapping with LINQ to Entities and the Entity Framework
See also: Extending NerdDinner: Exploring Different Database Options


Monday, May 24, 2010 12:30:13 PM (Pacific Standard Time, UTC-08:00)  #    Comments [0]    |   | 
 Wednesday, March 03, 2010
Wednesday, March 03, 2010 11:56:29 PM (Pacific Standard Time, UTC-08:00)  #    Comments [0]    | 
 Friday, February 12, 2010
I was trying to align some text to an image vertically. I used the align attribute like this:
<img height="28" src="/images/connect-phone.gif" width="26" align="middle"> 234-234-2342

But this didn't work in Firefox or Safari. So I sought out the CCS alternative. I came across this article explaining how to do it: http://www.webmasterworld.com/forum83/6588.htm . Here is the code supplied to answer the same question I had:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN"
"http://www.w3.org/TR/html4/strict.dtd"><html>
<head>
<title></title>
<style type='text/css'>
body, html {
height:100%; /*fill the viewport*/
}
#container{
height:100%; /*fill the body*/
text-align: center; /*H-centering in early IE versions*/
}
#pinac {
width: 826px;
height: 155px;
position:relative; /*allows for top property to move the element*/
top:50%; /*moves it 50% of #container's height down the page*/
margin-top:-77px; /*pulls it back up by half it's height*/
margin-left: auto;margin-right: auto; /*H-centering in complaint browsers*/
background:#369;
color:#fff;
}
</style>
</head>
<body>
<div id="container">
<div id="pinac">This is your element.</div>
</div>
</body>
</html>

You've got to be kidding! Forget that. Instead I found I could just set align="absmiddle" in the image. This attribute solved my problem, like this:

<img height="28" src="/images/connect-phone.gif" width="26" align="absmiddle"> 234-234-2342

I know CSS has it's place but I'm still not much of a fan.

Friday, February 12, 2010 2:52:05 PM (Pacific Standard Time, UTC-08:00)  #    Comments [0]    | 
 Wednesday, December 23, 2009

To get the ASP error message and line number in code, do the following:

1. Go to Error pages
2. Under actions click Add
3. Enter status code 500.100
4. Select 'Execute URL on this site'
5. Enter your error page, i.e. 500.asp

Now the Server.GetLastError object will contain the full error information.

Wednesday, December 23, 2009 11:31:25 PM (Pacific Standard Time, UTC-08:00)  #    Comments [0]    |  |   | 
Copyright © 2012 Matt Lyons. All rights reserved.