在我的 ASP.NET 项目中。我把我的css文件放进去
\App_Themes\Default\theme.css
这就在我的项目文件夹下,其中包含所有 aspx、master、web.config 等。
如何使用 .Master 页面中的相对路径将其读入字符串?在 C# 中。
这应该返回您的 css 文件夹的完整路径
Server.MapPath("App_Themes\Default\theme.css")
更多信息可以在这里找到http://msdn.microsoft.com/en-us/library/ms178116.aspx
在 *.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");
(行为描述及两者的区别可参见:http ://www.andornot.com/blog/post/ResolveUrl-vs-ResolveClientUrl.aspx )