我应该在我的 MVC 视图中使用 Url.Content() 还是 ResolveUrl()? [英] Should I use Url.Content() or ResolveUrl() in my MVC views?

查看:38
本文介绍了我应该在我的 MVC 视图中使用 Url.Content() 还是 ResolveUrl()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当构建这样的代码时:

<script type="text/javascript" src="<%=ResolveUrl("~/js/js.js")%>"></script>

<input type="image" src="<%=ResolveUrl("~/img/submit.png")%>" />

我应该使用 Url.Content 还是 ResolveUrl()?有什么区别?

Should I use Url.Content or ResolveUrl()? What's the difference?

推荐答案

如果您在 MVC 应用程序中使用 IIS URL Rewriting,例如在内部将 http://yoursubdomain.example.com/MyController/MyAction 视为 http://hosted.example.com/yoursubdomain/MyController/MyAction,Url.Content() 将生成一个正确的子域相关链接.在这种情况下,ResolveUrl() 将生成错误链接.

If you're using IIS URL Rewriting within your MVC application, e.g. internally treating http://yoursubdomain.example.com/MyController/MyAction as http://hosted.example.com/yoursubdomain/MyController/MyAction, Url.Content() will generate a correct subdomain-relative link. ResolveUrl() will generate an incorrect link in this situation.

这篇关于我应该在我的 MVC 视图中使用 Url.Content() 还是 ResolveUrl()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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