检查 ASP.NET 页面是否存在预编译页面

发布于 2024-11-17 15:15:30 字数 428 浏览 10 评论 0原文

我想在打开 ASPX 文件之前检查它是否存在,因为它是动态加载的。通过使用以下代码,这应该很容易:

string directoryPath = Server.MapPath("~/Forms/");
string filePath = directoryPath + nameOfFile + ".aspx";
if (File.Exists(filePath))
{
  Response.Redirect("~/Forms/" + nameOfFile + ".aspx");
}

对于 IIS 中未由 aspnet_compiler.exe 预编译的网站,该代码可以正常工作。但如果我预编译它们(即使是同一个网站),页面就找不到了。通过预编译它们,磁盘上仍然存在虚拟文件,因此应该可以在文件系统上找到它们。

也许有人可以帮助我解决这个问题......

I would like to check if an ASPX file exists before I open it because it is loadded dynamically. That should be quite easy by using the following code:

string directoryPath = Server.MapPath("~/Forms/");
string filePath = directoryPath + nameOfFile + ".aspx";
if (File.Exists(filePath))
{
  Response.Redirect("~/Forms/" + nameOfFile + ".aspx");
}

For websites in IIS that are not precompiled by aspnet_compiler.exe that works. But if I precompile them (even the same website) the pages are not found anymore. By precompiling them there are still dummy files on the disk so that they should be found on the filesystem.

Perhaps someone can help me with this...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

动次打次papapa 2024-11-24 15:15:30

您可能需要更进一步并反映预编译的 dll,以查看它们是否包含您尝试加载的页面的类

You may have to take it a step further and reflect of the precompiled dlls to see if they contain the class of the page you are trying to load

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文