简体   繁体   中英

Asp.net MVC 5 controller from another assembly serving angular static file miss js and css

I have a project that contains the UI and a class library where I have shared views.

I'm using VirtualPathProvider to serve Razor pages as embedded resources and it works fine.

But on it class library now I have a angular app, ant it view.

I serve the static html file from angular using a MVC controller and it worked fine. The only one issue is the js and css files are missing because they are referenced as relative path in the same folder level of index.html, but the static files requests are not handled by Asp.Net pipeline.

Some similar questions sujest to use System.Web.Handlers.TransferRequestHandler to catch the static files request, but it didn't work for me . I put the config on my web.config like

<add name="scripts" path="/controller/action/*" verb="GET" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0"/>

我已将其更改为使用剃刀索引,在该索引中,我使用@ Script.Render方法将对脚本的所有引用置于其中,因此它可以解决请求文件的问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM