簡體   English   中英

我可以通過Visual Studio從ASP.NET網站導出生成的html頁面嗎?

[英]Can I export generated html pages from ASP.NET website through Visual Studio?

我的朋友使用Visual Studio在ASP.NET中開發網站。 她只使用Master Page工具,而不是100%普通的HTML和CSS。

有沒有辦法根據主頁面將網站導出到HTML頁面?

如果沒有,它要么手動加載每個頁面並保存HTML,要么我寫了一個小應用程序。

或者,有沒有人知道實現類似的工具?

我真的不知道如何將整個網站導出到本地副本。

然而有工具 - 網站下載。 我知道一個 - TeleportPro,應該有其他人。 檢查它們是否適合您。

Visual Studio沒有開箱即用的功能。 但是,應該可以編寫一個遍歷站點地圖的工具,從響應對象捕獲渲染的html,然后將其寫入文件。

如果您想嘗試,可以給Macromedia Dreamweaver一個機會。 它適合客戶端和服務器端頁面開發。

使用MasterPages時,MasterPage的內容將與服務器端的內容頁面合並(在預編譯或頁面的第一次請求時)。 因此,您需要在某些時候通過aspnet_compile編輯內容頁面和MasterPage。 請參閱此MSDN文章的“運行時行為”部分。

您的朋友可能想要使用舊式服務器端包含(這實質上是MasterPage為您做的事情):

<!--#include virtual="/includes/header.html" -->
<!--#include virtual="/includes/nav.html" -->

<p> content </p>

<!--#include virtual="includes/footer.html" -->

如果這被您選擇的Web服務器/主機阻止(有些出於安全原因禁用它),那么我將創建一個主索引頁面並使用Ajax調用來填充內容DIV。 當然,如果禁用Javascript,您的訪問者將看不到任何內容。

我想你需要自己動手做這個。 此函數訪問URL並獲取內容:

  Public Shared Function GetHTTPContent(ByVal url As String) As String
    Dim req As WebRequest = System.Net.HttpWebRequest.Create(url)
    Dim encode As System.Text.Encoding = System.Text.Encoding.GetEncoding("utf-8")
    Dim sr As New StreamReader(req.GetResponse().GetResponseStream(), encode)
    Dim HTTPContent As String = sr.ReadToEnd

    sr.Close()
    sr.Dispose()

    Return HTTPContent

End Function

這是我的快速解決方案,可以抓取您的本地網站獲取.aspx文件,並在html旁邊生成.html文件。

protected void ButtonGenerate_Click(object sender, EventArgs e)
{
    RecursivelyGenerateHtmlFiles(Server.MapPath("~/"), new DirectoryInfo(Server.MapPath("~/")));
}

private void RecursivelyGenerateHtmlFiles(string root, DirectoryInfo folder)
{
    foreach (var aspxPage in folder.GetFiles("*.aspx"))
    {
        var destination = aspxPage.FullName.Substring(0, aspxPage.FullName.Length - 4) + "html";

        if (File.Exists(destination))
            File.Delete(destination);

        var url = "http://" + Request.Url.Authority + "/" + aspxPage.FullName.Replace(root, "");
        var request = HttpWebRequest.Create(url);

        File.WriteAllText(destination, new StreamReader(request.GetResponse().GetResponseStream()).ReadToEnd());
    }

    foreach (var subDirectory in folder.GetDirectories())
    {
        RecursivelyGenerateHtmlFiles(root, subDirectory);
    }
}

為我工作。

此外,您可以編輯.bat文件以生成包含您站點中所有.html文件的文件夾。 在為廣告素材提供廣告素材時,這非常有用。

set folder="Generated"
cd /d %folder%
for /F "delims=" %%i in ('dir /b') do (rmdir "%%i" /s/q || del "%%i" /s/q)
cd /d ..
xcopy /r /d /i /s /y /exclude:exclude.txt PAHtml Generated

這是要使用的exclude.txt文件

.dll
.cs\
.aspx
.pdb
.csproj
.user
.vspscc
.config

這些存在很多,這里有一個:

HTTrack網站復印機

這也稱為蜘蛛俠,因為它與搜索引擎的作用相同。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM