为了获得完全合格的应用程序路径,我编写了一个函数:
public class Generic
{
public static string FullyQualifiedApplicationPath
{
get
{
//Return variable declaration
string appPath = string.Empty;
//Getting the current context of HTTP request
var context = HttpContext.Current;
//Checking the current context content
if (context != null)
{
//Formatting the fully qualified website url/name
appPath = string.Format("{0}://{1}{2}{3}",
context.Request.Url.Scheme,
context.Request.Url.Host,
context.Request.Url.Port == 80
? string.Empty
: ":" + context.Request.Url.Port,
context.Request.ApplicationPath);
}
if (appPath.EndsWith("/"))
appPath = appPath.Substring(0, appPath.Length - 1);
return appPath;
}
}
}
当我在<head>
标签中使用它时,<%=%>
我得到不同的输出。
<link href="<%= Generic.FullyQualifiedApplicationPath %>/Styles/StyleSheet.css" rel="stylesheet" type="text/css" />
<script src="<%= Generic.FullyQualifiedApplicationPath %>/Scripts/jquery-1.7.2.min.js" type="text/javascript"></script>
html输出:
<link href="<%= Generic.FullyQualifiedApplicationPath %>/Styles/StyleSheet.css" rel="stylesheet" type="text/css" />
<script src="http://localhost:2093/SourceOne/Scripts/jquery-1.7.2.min.js" type="text/javascript"></script>
只是徘徊为什么asp.net引擎发送<%= Generic.FullyQualifiedApplicationPath %>
给客户端。
--新泽西州