2009-05-26 30 views
5

我的朋友使用Visual Studio在ASP.NET中开发网站。她只使用Master Page功能,除此之外它是100%正常的HTML和CSS。我可以通过Visual Studio从ASP.NET网站导出生成的html页面吗?

有没有办法根据主页面将网站导出到HTML页面?

如果没有,它会手动加载每个页面并保存HTML,或者我写一个小程序来完成它。

另外,有没有人知道一个工具来实现类似的东西?

+0

一个非常有趣的问题! – User 2009-05-26 14:48:55

+0

我很高兴你编辑了标题。我认为“应该把'HTML页''后我发布:) – joshcomley 2009-05-26 14:50:39

+0

我澄清了你的标题。 – Soviut 2009-05-26 14:51:09

回答

1

Visual Studio不具备开箱即用功能。但是,应该可以编写一个遍历站点地图的工具,捕获响应对象中呈现的HTML,然后将其写入文件。

1

我真的不知道如何将整个站点导出到本地副本。

然而,有工具 - 网站下载。我知道一个 - TeleportPro,应该有其他人。如果它听起来像是一个选项,请检查它们。

1

如果您喜欢试验,可以给Macromedia Dreamweaver一个镜头。它迎合了客户端和服务器端的页面开发。

1

当使用MasterPages时,MasterPage的内容与服务器端的内容页面(在预编译或页面的第一个请求时)合并。所以你需要在某个时候通过aspnet_compile编译内容页面和母版页。请参阅this MSDN article的“运行时行为”部分。

你的朋友可能要使用老式的服务器端包含(这基本上是什么母版是反正在为你做):

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

<p> content </p> 

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

如果这是你选择的Web服务器/主机阻塞(一些禁用它出于安全原因),那么我会创建一个主索引页面,并使用Ajax调用来填充内容DIV。当然,如果Javascript被禁用,您的访问者将看不到任何内容。

1

我认为你需要为这一个推出自己的产品。这个函数访问一个网址,并得到内容:

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 
0

这是我的快速解决方案,它抓取本地网站的.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 

这里是排除。txt文件使用

.dll 
.cs\ 
.aspx 
.pdb 
.csproj 
.user 
.vspscc 
.config 
相关问题