解决方案 »
- visual studio 2008教程
- 什么时候用视图 是什么时候用存储过程 什么时候用函数
- C#常用的程序打包软件
- MS-SQL中修改性别
- |zyciis| 如何最好的判断context.Request.RawUrl指定的地方是否在/Upload/Material/目录中的对像,谢谢
- 问一个问题!我的xp系统里现在装的有vs2003,vs2005(且带有ajax1.1开发包)现在我想再装一个vs2008上去!不知道装了2008后我的2005下装的ajax1.1开发包还有没有用!~
- 网站开发时这样会影响运行效率吗??
- 大家好,给我看看为什么数登录失败
- “System.Data.OleDb.OleDbDataReader”并不包含对“Item”的定义??
- treeview中还没解决的问题
- 静态方法如何实现文件下载?
- 实例化dataset中的查询
public string Content(string contentPath) {
return Content(contentPath, RequestContext.HttpContext);
} internal static string Content(string contentPath, HttpContextBase httpContext) {
if (String.IsNullOrEmpty(contentPath)) {
throw new ArgumentException(MvcResources.Common_NullOrEmpty, "contentPath");
} if (contentPath[0] == '~') {
return PathHelpers.GenerateClientUrl(httpContext, contentPath);
}
else {
return contentPath;
}
}
public static string GenerateClientUrl(HttpContextBase httpContext, string contentPath) {
if (String.IsNullOrEmpty(contentPath)) {
return contentPath;
} // many of the methods we call internally can't handle query strings properly, so just strip it out for
// the time being
string query;
contentPath = StripQuery(contentPath, out query); return GenerateClientUrlInternal(httpContext, contentPath) + query;
} private static string GenerateClientUrlInternal(HttpContextBase httpContext, string contentPath) {
if (String.IsNullOrEmpty(contentPath)) {
return contentPath;
} // can't call VirtualPathUtility.IsAppRelative since it throws on some inputs
bool isAppRelative = contentPath[0] == '~';
if (isAppRelative) {
string absoluteContentPath = VirtualPathUtility.ToAbsolute(contentPath, httpContext.Request.ApplicationPath);
string modifiedAbsoluteContentPath = httpContext.Response.ApplyAppPathModifier(absoluteContentPath);
return GenerateClientUrlInternal(httpContext, modifiedAbsoluteContentPath);
} // we only want to manipulate the path if URL rewriting is active, else we risk breaking the generated URL
NameValueCollection serverVars = httpContext.Request.ServerVariables;
bool urlRewriterIsEnabled = (serverVars != null && serverVars[_urlRewriterServerVar] != null);
if (!urlRewriterIsEnabled) {
return contentPath;
} // Since the rawUrl represents what the user sees in his browser, it is what we want to use as the base
// of our absolute paths. For example, consider mysite.example.com/foo, which is internally
// rewritten to content.example.com/mysite/foo. When we want to generate a link to ~/bar, we want to
// base it from / instead of /foo, otherwise the user ends up seeing mysite.example.com/foo/bar,
// which is incorrect.
string relativeUrlToDestination = MakeRelative(httpContext.Request.Path, contentPath);
string absoluteUrlToDestination = MakeAbsolute(httpContext.Request.RawUrl, relativeUrlToDestination);
return absoluteUrlToDestination;
}