KeesDijk
KeesDijk

Reputation: 2329

Asp.net link to file: in IE strange behaviour

We are working on migrating an older ASP.Net application to the cloud and for that we did several things also updated the application to use a newer .net framework.

Now we face a strange problem, in the application a link is created from data in the database. The html:

 <asp:HyperLink ID="linkProjectFolder" CssClass="imageLink" runat="server" ToolTip="Open de folder in de Windows Explorer">
     <asp:Image ID="Image1" runat="server" ImageUrl="~/pages/img/openHS.png" />
 </asp:HyperLink>

The code behind:

string url = string.Concat(((TextBox)viewINFO.FindControl("txtProjectmapBasePath")).Text, ((TextBox)viewINFO.FindControl("txtProjectmapPath")).Text);
HyperLink hl = (HyperLink)viewINFO.FindControl("linkProjectFolder");
if (hl != null)
{
   hl.NavigateUrl = Uri.EscapeUriString(@"file:///" + url);
}

Nothing special and this code has not changed between the old version and the new version. I know that this code does not work in firefox and chrome, but the old version does work in IE11.

Now from the enduser the old version in IE just works, if you click the link a windows explorer window is opened to the file path. For the same end user, from the same workstation with the same browser the new version does not work. When you click the link nothing happens.

Now the strange part, on my development machine, I simulate a network drive by mapping a folder to a drive letter (susbst N: c:\temp\Ndrive) when I try the link I see the same behavior as the end user, just nothing happens. Now if I unmap the drive, start the application and click the link, the link opens in the browser and I get a "page cannot be displayed". If I remap the drive at that moment, go back in the browser and retry the link it works.....

There are of course differences, the .net framework, IIS vs IISExpress vs IIS on azure, but as it is just a simple href I would say it must be client side. Also that the code sometimes works suggests that the urlencoding at least is correct (it does exactly the same as in the old version for the tested url's)

In the database the links are a path to a mapped drive so something like "N:\folder\folder 2\folder & folder\", that is correctly urlencoded and that only works half the time as described above. If I use a link to my C drive "C:\Temp" it never works, if I use "127.0.0.1/C$/Temp/" as link it always works but changing all the links in the database to use an IP address is not really the way we want to go.

After eliminating all the things above I have no clue on what could cause this behavior. Can anybody point me in the right direction ?

Upvotes: 4

Views: 209

Answers (1)

JohnH
JohnH

Reputation: 2133

Consider revising the asp:HyperLink tag with a nested asp:Image tag with one of these two (2) options:

1) Use an asp:HyperLink tag with ImageUrl property and remove the nested image tag. See this Microsoft Hyperlink.ImageUrl Property page for more information.

2) Use an asp:ImageButton tag with the ImageUrl property. See this SO question titled: how to link imagebutton to url visual developer for more information.

If none of these options resolves your problem, then you may have a file resource access issue rather than an ASP.NET syntax issue.

Upvotes: 3

Related Questions