积极答复者
背景文件的路径问题

问题
-
位于 解决方案 的 aaa 文件夹中, 有一个 aaa.ascx 文件, <div id = "ccc">, 在cs文件中,写下:
HtmlLink HtmlLink1 = new HtmlLink();
HtmlLink1.Href = "/aaa/cj/bbb.css";
HtmlLink1.Attributes.Add("rel", "stylesheet");
HtmlLink1.Attributes.Add("type", "text/css");
this.Page.Header.Controls.Add(HtmlLink1);
在 bbb.css 中 定义div 背景图:
#ccc
{
background-image: url('../../aaa/Images/login_bg.png');}
}
以上写法, 在vs2010beta1 中通过.
在vs2010beta2中, 运行时,看不到背景图, 不知道哪里路径出错了.- 已编辑 lfj0912 2009年11月3日 2:48
- 已移动 孟宪会Moderator 2009年11月3日 9:28 (发件人:Web 相关讨论(IIS,IE8等))
答案
-
可能你的iis把js也交给了.net处理 当你添加了Forms验证未登录也就无法访问了
你可以添加
<location path= "~/aaa/cj/Login.js">
<system.web>
<authorization>
<allow users= "*"/>
</authorization>
</system.web>
</location>
这个节点到Configuration节点下
Wenn ich dich hab’,gibt es nichts, was unerträglich ist.坚持不懈!My blog~~~- 已标记为答案 lfj0912 2009年11月3日 12:12
-
全部回复
-
你改成
HtmlLink1.Href = "~/aaa/cj/bbb.css";
#ccc
{
background-image: url('../Images/login_bg.png');}
}
试试呢?
Wenn ich dich hab’,gibt es nichts, was unerträglich ist.坚持不懈!My blog~~~ -
谢谢孟老师!
private void InsertCJ()
{
String Root = Request.ApplicationPath == "/" ? "" : Request.ApplicationPath;HtmlGenericControl UserHgc = new HtmlGenericControl("Script");
UserHgc.Attributes.Add("src", Root + "/aaa/cj/Login.js");
UserHgc.Attributes.Add("type", "text/javascript");
UserHgc.Attributes.Add("charset", "gb2312");
this.Page.Header.Controls.Add(UserHgc);HtmlLink HtmlLink2 = new HtmlLink();
HtmlLink2.Href = Root + "/aaa/cj/Stylesheet1.css";
HtmlLink2.Attributes.Add("rel", "stylesheet");
HtmlLink2.Attributes.Add("type", "text/css");
this.Page.Header.Controls.Add(HtmlLink2);
}
这样照样无法找到js程序. aaa不是工程名称, 是工程项目下的一个 子文件夹.
等晚上我重新装一下系统, 再测试看看. -
HtmlLink HtmlLink1 = new HtmlLink();
HtmlLink1.Href = "~/aaa/cj/bbb.css";HtmlLink1.Attributes.Add("rel", "stylesheet");
对于Script
HtmlLink1.Attributes.Add("type", "text/css");
this.Page.Header.Controls.Add(HtmlLink1);
这种方式是完全可以的
HtmlGenericControl UserHgc = new HtmlGenericControl("Script");
UserHgc.Attributes.Add("src", HostingEnvironment.ApplicationVirtualPath+"/aaa/cj/Login.js");
Wenn ich dich hab’,gibt es nichts, was unerträglich ist.坚持不懈!My blog~~~ -
谢谢孟老师!
private void InsertCJ()
{
String Root = Request.ApplicationPath == "/" ? "" : Request.ApplicationPath;HtmlGenericControl UserHgc = new HtmlGenericControl("Script");
UserHgc.Attributes.Add("src", Root + "/aaa/cj/Login.js");
UserHgc.Attributes.Add("type", "text/javascript");
UserHgc.Attributes.Add("charset", "gb2312");
this.Page.Header.Controls.Add(UserHgc);HtmlLink HtmlLink2 = new HtmlLink();
HtmlLink2.Href = Root + "/aaa/cj/Stylesheet1.css";
HtmlLink2.Attributes.Add("rel", "stylesheet");
HtmlLink2.Attributes.Add("type", "text/css");
this.Page.Header.Controls.Add(HtmlLink2);
}
这样照样无法找到js程序. aaa不是工程名称, 是工程项目下的一个 子文件夹.
等晚上我重新装一下系统, 再测试看看.这样照样无法找到js程序?是你程序本身有问题吧js文件里面只写一行alert("ok")测试
【孟子E章】 -
可能你的iis把js也交给了.net处理 当你添加了Forms验证未登录也就无法访问了
你可以添加
<location path= "~/aaa/cj/Login.js">
<system.web>
<authorization>
<allow users= "*"/>
</authorization>
</system.web>
</location>
这个节点到Configuration节点下
Wenn ich dich hab’,gibt es nichts, was unerträglich ist.坚持不懈!My blog~~~- 已标记为答案 lfj0912 2009年11月3日 12:12
-