AngularJs访问和MVC4服务器时Web应用程序中的路径解析(Path resolution in Web application when AngularJs is accessing and

编程入门 行业动态 更新时间:2024-10-21 16:21:56
AngularJs访问和MVC4服务器时Web应用程序中的路径解析(Path resolution in Web application when AngularJs is accessing and MVC4 server)

我试图通过混合ASP.Net MVC4和AngularJS来创建模块化应用程序。 MVC所做的是它允许我们像下面那样进行路径分离。

主屏http://127.0.0.1:81/

当用户登录时,我为他们提供如下的基本路径

`http://127.0.0.1:81/shipper/#/operations/home`

要么

`http://127.0.0.1:81/client/#/orders/home`

所以我得到了每种类型用户的基本屏幕模板,从那时起,它就是一个SPA,它接管模板,有时根据需要共享一个公共视图。

现在我遇到的问题是,当我必须引用任何服务器对象,如Web服务器上的图像,它们都位于root\themes\images\image1.jpg

fiddler中的图像URI已解析为http://127.0.0.1:81/client/themes/images/image1.jpg

代替

http://127.0.0.1:81/themes/images/image1.jpg

这显然意味着这将失败。

我的HTML如下所示:

<img class="media-object" src="themes/images/img180x120.png" />

有没有办法可以覆盖它以强制它忽略路径中的/ shipper / / client?

此致,Kiran

I am trying to create a modular applications by mixing the ASP.Net MVC4 and AngularJS. what MVC does is that it allows us to have a path separation like below.

Home screen http://127.0.0.1:81/

when a user logs in, i provide them with a base path as below

`http://127.0.0.1:81/shipper/#/operations/home`

or

`http://127.0.0.1:81/client/#/orders/home`

so I get a base screen template per type of user and from then on it is a SPA that takes over on the template which sometimes share a common view based om the need.

now the issue i am having is that when i have to reference any server object like image on the web server that are all located in the root\themes\images\image1.jpg

the image URI in the fiddler is getting resolved to http://127.0.0.1:81/client/themes/images/image1.jpg

instead of

http://127.0.0.1:81/themes/images/image1.jpg

which obviously means this will fail.

my HTML looks like below:

<img class="media-object" src="themes/images/img180x120.png" />

is there a way I can override this to force it to ignore the /shipper or /client from the path ?

Regards, Kiran

最满意答案

事实证明,在url之前,使用/将使其成为相对于主机服务器的路径。

As i turns out just preceeding the url with a / will make it a path relative the the host server.

更多推荐

本文发布于:2023-07-04 17:20:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1027009.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   路径   服务器   Web   AngularJs

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!