.net导出页面为html,我可以通过Visual Studio从ASP.NET网站导出生成的html页面吗?

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值