2012-02-10 40 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 

注:很多网站骗与此属性仅返回当前时间。

相关问题