开发者

How do I get css links to resolve correctly when adding a PathInfo value?

I have an asp.net 3.5 app. when I try to add a value to the url to be picked up in Request.PathInfo, i lose anything linked in head because the locations are resolved as relative paths.

master page looks like this:

<head id="Head1" runat="server">
    <link rel="stylesheet" href='~/App_Themes/main/style.css' type="text/css"  />
</head>

and renders like this

<head id="ctl00_ctl00_Head1">
    <link rel="stylesheet" href="../App_Themes/main/style.css" type="text/css" />
</head>

and so when i go to

http://localhost:5000/project/folder/edit.aspx/555

the browser is looking for the stylesheet at

http://localhost:5000/project/folder/App_Themes/main/style.css

instead of

http://localhost:5000/project/App_Themes/main/style.css

is it automatic behavior to resolve with a relative path? can I change it? is this something the previous developer is doing that i haven't found?

--- edit ---

i took the suggestion below and added a base element like so

<base id="ctl00_ctl00_baseElement" href="http://localhost:5000/project/"></base>

but my links开发者_Python百科 still don't work because asp.net is insistent on rendering the urls as relative paths unless the href starts with /, but in both cases i end up one level too high now.

http://localhost:5000/App_Themes/main/style.css


Use:

<base href="http://yourdomain.com">
<link rel="stylesheet" href="/App_Themes/main/style.css" type="text/css" />


Apparently when the head element is defined as a server control, link elements within are automatically parsed and resolved by the server. So the solution is to have the head element as a standard html control only or possibly manually add your link elements. I bailed on the PathInfo idea I was pursuing so I didn't get that far.


I resolve this issue, adding an html 'base' tag, Using method: Page.ResolveUrl("~") to resolve the base url of the site. Works well on both localhost and server:

    <base href="<%=ResolveUrl("~")%>" />
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜