2012-02-10 64 views
1

我有一個問題在我的項目找到一個站點的最後修改日期..如何查找網頁的上次修改日期?

任何代碼,發現在asp.net提前

感謝..

+1

http://msdn.microsoft.com/en-us/library/system.io.filesysteminfo.lastwritetime.aspx 'System.IO.File.GetLastWriteTime(Request.PhysicalPath).ToString();' – 2012-02-10 12:54:24

回答

1

看看這個問題

How can you mine the "Last Modified Date" for an ASP.NET page which is based on a Master Page?

你需要的基本代碼是這樣

Dim strPath As String = Request.PhysicalPath 
Label1.Text = "Modified: " + System.IO.File.GetLastWriteTime(strPath).ToString() 
+0

i想要獲得像谷歌,雅虎,認識像.. – Prabhakaran 2012-02-10 12:57:54

+0

網站的更新時間爲什麼不在第一時間提到你的問題?所以你想知道不是當前頁面的網頁的最後修改時間?你想讓用戶從可用頁面列表中選擇或讓他在文本框中輸入url嗎? – 2012-02-10 13:17:30

0

FileInfo.LastWriteTime應該給你你需要的東西:

System.IO.File.GetLastWriteTime(Request.PhysicalPath).ToString(); 

據對對方的回答您的評論,你不是想要得到任何的網站(而不是你自己的ASP的最後修改時間.NET頁面)。你可以使用Net.HttpWebRequest來請求給定的URL來獲取HttpResponseLastModified屬性:

Protected Sub GetLastModifiedTimeOfWebPage(sender As Object, e As EventArgs) 
    Dim url = Me.TxtURL.Text.Trim 
    If Not url.StartsWith("http:") Then url = "http://" & url 
    Dim ResponseStatus As System.Net.HttpStatusCode 
    Dim lastModified As Date 
    Try 
     lastModified = RequestLastModified(url, ResponseStatus) 
    Catch ex As System.Exception 
     ' log and/or throw 
     Throw 
    End Try 
    If ResponseStatus = Net.HttpStatusCode.OK Then 
     Me.LblLastModified.Text = lastModified.ToString 
    End If 
End Sub 

Public Shared Function RequestLastModified(_ 
    ByVal URL As String, _ 
    ByRef retStatus As Net.HttpStatusCode 
) As Date 
    Dim lastModified As Date = Date.MinValue 
    Dim req As System.Net.HttpWebRequest 
    Dim resp As System.Net.HttpWebResponse 
    Try 
     req = DirectCast(Net.HttpWebRequest.Create(New Uri(URL)), Net.HttpWebRequest) 
     req.Method = "HEAD" 
     resp = DirectCast(req.GetResponse(), Net.HttpWebResponse) 
     retStatus = resp.StatusCode 
     lastModified = resp.LastModified 
    Catch ex As Exception 
     Throw 
    Finally 
     If resp IsNot Nothing Then 
      resp.Close() 
     End If 
    End Try 

    Return lastModified 
End Function 

注:很多網站騙與此屬性僅返回當前時間。

相關問題