波浪符号意义 [英] significance of tilde sign

查看:256
本文介绍了波浪符号意义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 路径字符串= context.Server.MapPath(〜/温度);

 路径字符串= context.Server.MapPath(/温度);

相同?

我知道,'〜'重新presents根,但想知道差异体重〜/文件夹 /文件夹


解决方案

  

绝对和服务器控件相对路径引用有
  以下缺点:


  
  

      
  • 绝对路径不是应用程序之间进行移植。如果移动
      应用程序的绝对路径指向,链接将中断。


  •   
  • 在客户端元件的样式

    相对路径可以是难
      如果移动资源或页面不同的文件夹维护。


  •   

  
  

要克服这些缺点,包括ASP.NET Web应用程序
  根运算符(〜),您可以指定服务器的路径时使用
  控制。 ASP.NET解析〜操作者当前的根
  应用程序。


请参阅 http://msdn.microsoft。 COM / EN-US /库/ ms178116(v = VS.100)的.aspx

〜/ 解析为应用程序根目录。

/ 解析为站点根目录。

当一个服务器资源(如控制或视图)呈现,〜/ 路径解析为基于应用程序的结构和上下文网站根目录路径(自〜/ 是没有意义的网页浏览器)。

要简化,应用程序根目录(〜/ )几乎总是在ASP.Net应用程序的正确选择(包括Web窗体和MVC)。

string path = context.Server.MapPath("~/Temp");

or

string path = context.Server.MapPath("/Temp");

are same ?

I know that '~' represents root but want to know diff bw ~/folder and /folder

解决方案

Absolute and relative path references in a server control have the following disadvantages:

  • Absolute paths are not portable between applications. If you move the application that the absolute path points to, the links will break.

  • Relative paths in the style of client elements can be difficult to maintain if you move resources or pages to different folders.

To overcome these disadvantages, ASP.NET includes the Web application root operator (~), which you can use when specifying a path in server controls. ASP.NET resolves the ~ operator to the root of the current application.

See http://msdn.microsoft.com/en-us/library/ms178116(v=vs.100).aspx

~/ resolves to the application root.

/ resolves to the site root.

When a server resource (like a control or view) is rendered, ~/ paths are resolved to site root paths based on the structure and context of the application (since ~/ is meaningless to a web browser).

To simplify, application root (~/) is almost always the correct choice in ASP.Net applications (both web forms and MVC).

这篇关于波浪符号意义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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