且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在asp.net中页面重定向时访问一个文件夹的图像文件夹和另一个文件夹中的脚本

更新时间:2022-10-22 20:50:58

你好,



MicroContactForm中设计的页面似乎是指MicroContactForm下各个子文件中不存在的图像和文字。您可以尝试做的是将这两个文件夹中的所有图像,脚本,CSS移出到admin下的文件夹中并使用相对路径,以便浏览器能够正确加载这些工件。



 admin 
static
js
css
images
Microsite
1
2
...
60
MicroContactForm
1
2
...
10

>


在您的页面中使用类似于下面所示的代码片段来引用这些工件

 <   script     type   =  text / javascript    src   =  / static / js / somescript.js     /  >  
< link type = text / css href = / static / css / somestyle.css />
< img src = / static / images / someimage.png />



问候,


解决方法是使用
<![CDATA [< ;%=在路径中的Request.ApplicationPath %> ]] >  

,怎么样?

Folowings是我在ASP.net的主页面中提供的链接的示例,其中内容根目录下的文件夹

 <   script     type   =  text / javascript    src   =  <% = Request.ApplicationPath %>  /Contents/javascript/jquery/jquery-1.6.1.min.js >  <   / script  >  
< script type = text / javascript src = <% = Request.ApplicationPath %> / Contents / javascript / jquery / ui / external /jquery.bgiframe-2.1.2.js\"> < / script >



观察链接,你会发现

<![CDATA [<%= Request.ApplicationPath %> 页面请求时,路径中的>  

代替绝对路径(〜)或相对路径... /从一条路径到其他路径,dotnet itselt将管理与路径相关的事物。



使用此类路径时可能会出现以下错误

Quote:

此文件中不允许使用代码块



如果是,则替换=#

< script type =text / javascriptsrc =<%#Request.ApplicationPath%> /Contents/javascript/jquery/jquery-1.6.1。 min.js>< / script> 





并用于vb.net

 Me.Page。 Header.DataBind()



 this.Page.Header.DataBind()

for C#in代码背后





希望这可以帮到你 - 享受编码报价>

Hello,
In my web application There is a folder named admin under root directory. In admin folder there are 2 sub folder named 1. Microsite(containing 60 sub folders named 1,2,3,4,5...60) and 2. MicroContactForm (containing 10 sub folders named 1,2,3,4,5...10).

Now my problem is that when I try to redirect a page from Microsite -> sub folder(1) page to MicroContactForm -> sub folder(3) page, imges and jquery script are not loded proper that resides in Microsite -> sub folder(1).

What should i do now, Help me.... it''s urgent please

Thanks

Sunil sharma

Hello,

It appears that the pages designed in MicroContactForm are referring to images andor scrips not present in the respective subfodlers under MicroContactForm. What you can try doing is to move all images, scripts, css out of these two folders out into a folder under admin and use relative paths so that browser will be able to load those artifacts correctly.

admin
  static
    js
    css
    images
  Microsite
    1
    2
    ...
    60
  MicroContactForm
    1
    2
    ...
    10



In your pages use code snippets similar to shown below to refer these artifacts

<script type="text/javascript" src="/static/js/somescript.js" />
<link type="text/css" href="/static/css/somestyle.css" />
<img src="/static/images/someimage.png" />


Regards,


The solution for this is to use
<![CDATA[<%=Request.ApplicationPath%>]]>

in path, How?
Folowings are the example of the links i have provided in Master page of ASP.net where Contents the folder at root directory

<script type="text/javascript" src="<%=Request.ApplicationPath%>/Contents/javascript/jquery/jquery-1.6.1.min.js"></script>
 <script type="text/javascript" src="<%=Request.ApplicationPath%>/Contents/javascript/jquery/ui/external/jquery.bgiframe-2.1.2.js"></script>


Observe the link you will find the

<![CDATA[<%=Request.ApplicationPath%>]]>

in the path instead of absolute path ("~") or relative path ".../" when page request from one path to other path the dotnet itselt will manage the things related to path.

You may get following error while using such path

Quote:

Code-blocks are not allowed in this file


if so the replace = with #

<script type="text/javascript" src="<%#Request.ApplicationPath%>/Contents/javascript/jquery/jquery-1.6.1.min.js"></script>



and use for vb.net

Me.Page.Header.DataBind()


and

this.Page.Header.DataBind()

for C# in code behind


Hope this may help you-Enjoy Coding