HttpContext.Current.Request.Url.IsFile当链接ASPX页面
问题描述:
我打形式的本地URL返回FALSE Global.asax文件,并随后使用做的东西,如果它是一个aspx文件(只有一个aspx文件):HttpContext.Current.Request.Url.IsFile当链接ASPX页面
HttpContext.Current.Request.Url.IsFile
它始终解析为false
不过,我不知道为什么。我完全global.asax
代码:
if(HttpContext.Current.Request.Url.IsFile)
{
if(File.Exists(HttpContext.Current.Request.Url.LocalPath))
{
if(new FileInfo(HttpContext.Current.Request.Url.LocalPath).Extension.Equals("aspx"))
{
DoSomethingWithThePagesURL();
}
}
}
答
你领看看Documentation for IsFile Property?。从文档中看来非常明显,Http:
不是File:
。
当Scheme属性等于UriSchemeFile时,IsFile属性为true。
using System;
public class Program
{
public static void Main()
{
Uri uriAddress2 = new Uri("file://server/filename.ext");
Console.WriteLine(uriAddress2.LocalPath);
Console.WriteLine("Uri {0} a UNC path", uriAddress2.IsUnc ? "is" : "is not");
Console.WriteLine("Uri {0} a local host", uriAddress2.IsLoopback ? "is" : "is not");
Console.WriteLine("Uri {0} a file", uriAddress2.IsFile ? "is" : "is not");
}
}
结果:
\服务器\ FILENAME.EXT
URI是一个UNC路径
URI是不是本地主机
URI是文件
看看这里一些有用的东西.. http://wdevs.blogspot.com/2009/03/url-properties-of-request-to-aspnet.html – MethodMan 2014-12-04 23:05:15