2014-12-04 101 views
1

我打形式的本地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(); 
     } 
    } 
} 
+0

看看這裏一些有用的東西.. http://wdevs.blogspot.com/2009/03/url-properties-of-request-to-aspnet.html – MethodMan 2014-12-04 23:05:15

回答

1

你領看看Documentation for IsFile Property?。從文檔中看來非常明顯,Http:不是File:

當Scheme屬性等於UriSchemeFile時,IsFile屬性爲true。

DotNetFiddle Example

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是文件