views:

604

answers:

2

I have an ASP.NET application originally deployed to a .Net 1.1 Framework on Windows 2000 server which i'm now using on a Windows 2008 Server using 2.0.50727. We use the tilde (~) to resolve to an absolute path in many areas of the application and it works for things like asp:hyperlink controls (with run-at server tags), but for our bound datagrid controls which are using HyperLinkColumns to create links based on ID values returned from our database, the tilde is getting written to the page.

This code:

HyperLinkColumn oLink = new HyperLinkColumn();
oLink.DataNavigateUrlField = "IdField";
oLink.DataNavigateUrlFormatString = "~/Here{0}.aspx";

is dumping this to the page:

<a href="~/Here171201.aspx">

What changed between versions of IIS or .NET Framework could be causing this functionality to no longer work? The Tilde was definitely resolving in 1.1 - I have the exact same code deployed on a dozen 1.1 Framework servers in our organization. Unfortunately, the class that sets the DataNavigateUrlFormatString doesn't have access to the Page, so I'll have to do some kludging to insert the Page.ResolveUrl work around...

+3  A: 

I'm not aware of anything changing, but I don't use HyperLinkColumns (I prefer the control which the Template column provides) so I've not looked for any changes .

One possibility as a proverbial band aid is to change this line:

oLink.DataNavigateUrlFormatString = "~/Here{0}.aspx";

to this:

oLink.DataNavigateUrlFormatString = Page.ResolveUrl("~/Here{0}.aspx");

If memory serves there was some issues when going to Master Pages and using the '~' from User Controls, but it's been a while since I read anything like that.

Stephen Wrighton
+1  A: 

I don't think that the HyperlinkColumn of a Datagrid automatically resolves the URL into an absolute path. IIRC, the DataNavigateUrlFormatString property internally calls String.Format() only on the supplied format. Are you sure this worked correctly on .NET 1.1? IIRC, .NET 1.1 did not have tilde-based automatic URL resolution.

In my opinion, you should use the solution presented by Stephen (call Page.ResolveUrl manually.)

Cerebrus