开发者

ASP.Net Hyperlink navigation URL not including server name

开发者 https://www.devze.com 2023-01-30 07:26 出处:网络
This might be a ridiculously easy question, but it has me stumped.I have a web form where I\'m trying to create a hyperlink in the code behind to a file server share, e.g. file://myServer/Shared/, but

This might be a ridiculously easy question, but it has me stumped. I have a web form where I'm trying to create a hyperlink in the code behind to a file server share, e.g. file://myServer/Shared/, but when the page is rendered, the link doesn't include the server name, i.e. file:///Shared/. I don't know why this happens. Any help or insight is appreciated.

UPDATE:

Sure, here is the snippet where the link is being set.

    //The link is embedded in a table
    HyperLink link = (HyperLink)e.Row.Cells[1].Controls[0];
    link.NavigateUrl = @"file://myServer/Shared/";

As a test, I assigned the link to a string value and the link prints the expected url.

string foo = link.NavigateUrl;

//Displays this
"file://myServer/Shared/"

I don't know why this doesn't appear when the link is rendered in the final page.

UPDATE 2:

Ok, so I know I have to set the absolute path in the code-behind, I thought that's what I was doing, but it still w开发者_StackOverflowon't render correctly.

UPDATE 3:

I followed pjacobs suggestion about setting the test property and it was actually a step in the right direction. I have the following:

link.Text = "<a href=\"file:\\myServer\\Shared\">link text</a>";

Now the link gets rendered as follows: file:///myServer/Shared. I'm almost there except it gives the extra '/' in front of the server name. I'll keep playing with it, this seems like it should be so simple, I don't understand why ASP.Net renders the URL differently.


You have to set the Text property of the HyperLink... link.Text = "whatever"


Are the resources inside the project? If so: you need to use ResolveUrl to resolve the "web location" of the resource. http://msdn.microsoft.com/en-us/library/system.web.ui.control.resolveurl.aspx

if you're using an asp.net control you shouldn't need to use the resolve url, but you need to refer to the location of the file relative to the path of the project.

If not: Did you give the proper read account to ASP.NET process? Use a virtual directory? http://www.dotnetspider.com/tutorials/AspNet-Tutorial-86.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消