如何在开发机器上的aspx页面中使用绝对url?
我发现自己在 aspx 页面中经常使用 ResolveUrl 函数,但解析的路径始终是相对的。 我希望能够让渲染的路径以常规的“http://localhost/myproject/”开头
如果我更改文件的层次结构,如何在不破坏任何代码的情况下实现这一目标? 编写一个函数并为页面上的每个目标链接调用它会不会效率低下?
I find myself using the ResolveUrl function a lot in my aspx pages but the resolved path is always relative. i would like to be able to have the rendered path start with the regular "http://localhost/myproject/"
How can i achieve that without breaking any code in case i change the hierarchy of my files?
Would it be inefficient to write a function and call it for every targeted link on the page?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
解析 url 时使用
~
。 它将始终转到应用程序根目录。示例
~/somedirectory/default.aspx
将解析为...
{applicationRoot}/somedirectory/default.aspx
您需要手动添加服务器地址:
Request.Url.Scheme + "://" + Request.Url.Host + ":" + Request.Url.Port
示例函数是
Use the
~
when you resolve the url. It will always go to the application root.Example
~/somedirectory/default.aspx
will resolve to...
{applicationRoot}/somedirectory/default.aspx
You will need to manually add the server address:
Request.Url.Scheme + "://" + Request.Url.Host + ":" + Request.Url.Port
A sample function would be
别介意伙计们,
我从 Rick Strahl 帖子 在线找到了一些代码,它似乎是我可能会在我的情况下使用的东西!
谢谢您的帮助
Never mind guys,
I found some code online from a Rick Strahl post and it seems to be something i might use in my case!
thanks for the help