T4MVC和虚拟目录 [英] T4MVC and virtual directory

查看:105
本文介绍了T4MVC和虚拟目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在项目中使用T4MVC.但在部署到虚拟目录例如"/app"后,当我运行该网站时,所有地址都是错误.例如,它不是content/site.css而是/app/content/site.css,而浏览器找不到.

例如我写:

<link href="@Links.Content.bootstrap_min_css" rel="stylesheet" type="text/css" />

呈现为

<link href="/app/Content/bootstrap.min.css" rel="stylesheet" type="text/css" />

代替

<link href="Content/bootstrap.min.css" rel="stylesheet" type="text/css" />

我应该如何解决此问题?

解决方案

通常,这是正确的行为.如果您的应用程序在虚拟目录/app下运行,则应该可以使用/app/content/site.css请求静态文件.因此,您的首要重点应该是试图了解为什么它不起作用.

如果您真的想更改此逻辑,请查看T4MVC.tt.hooks.t4中的ProcessVirtualPath.您可以更改路径的处理方式,并根据需要轻松地使其相对.更改此文件后,请确保重新运行T4MVC自定义工具.

I'm using T4MVC in my project . but after deploying to a virtual directory e.g "/app" when I run the site all addresses were wrong . for example instead of being content/site.css it's /app/content/site.css and the browser can't find it .

for example I write :

<link href="@Links.Content.bootstrap_min_css" rel="stylesheet" type="text/css" />

that renders to

<link href="/app/Content/bootstrap.min.css" rel="stylesheet" type="text/css" />

instead of

<link href="Content/bootstrap.min.css" rel="stylesheet" type="text/css" />

how should I fix this problem ?

解决方案

Normally, this is the correct behavior. If your app is running under the virtual directory /app, then static files should be able to be requested using /app/content/site.css. So your first focus should be on trying to understand why this is not working.

If you really want to change this logic, look at ProcessVirtualPath in T4MVC.tt.hooks.t4. You can change the way the path is handled, and easily make it relative if you like. Make sure to rerun the T4MVC custom tool after changing this file.

这篇关于T4MVC和虚拟目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆