2012-06-21 34 views
0

在我的ASP.NET項目中。我把我的CSS文件中如何從我的母版頁上相對讀取css文件?

\App_Themes\Default\theme.css 

這是對下與所有的ASPX,主人,我的web.config中的項目文件夾等

如何讀取到字符串中使用從相對尋路我.Master頁面?在C#中。

回答

1

在* .aspx頁面中:

<head runat="server"> 
    <link runat="server" href="~/App_Themes\Default\theme.css" 
      rel="stylesheet" type="text/css" /> 
</head> 

或者從後面的代碼:

string path = ResolveUrl("~/App_Themes\Default\theme.css"); 
// or 
string path = ResolveClientUrl("~/App_Themes\Default\theme.css"); 

(行爲和之間的差異說明twocan在這裏找到:http://www.andornot.com/blog/post/ResolveUrl-vs-ResolveClientUrl.aspx

+0

我必須做這在C# – Bill

+0

是的,它也應該工作 – codingbiz

+0

相應地更新我的答案 –