asp.net - 在 IIS 中的 .aspx 页面中使用 Python

标签 asp.net python iis

简要摘要:在 IIS 服务器上托管的网站上,独立​​的 Python 文件可以正确呈现,但在 .aspx 页面(而不是 VB)中使用 Python 会导致错误,指出 Python 不受支持语言,尽管(显然)已经使用 ActiveX 脚本引擎注册了它。我想让 Python 成为受支持的语言。

更多详情: 我有一个托管在 IIS 6.1 服务器上的网站,它可以正确解释和显示 .aspx 文件。我希望在 .aspx 文件中使用 Python 作为语言,而不是像我到目前为止那样使用 VB。

我已经成功地让独立的 Python 页面正确呈现 - 例如,网站上的一个文件包含以下代码:

print 'Content-type: text/html'
print

print '<HTML><HEAD><TITLE>Python Sample CGI</TITLE></HEAD>'
print '<BODY>'
print '<H1>This is a header</H1>'

print '<p>' #this is a comment
print 'See this is just like most other HTML'
print '<br>'
print '</BODY>'
当在网络浏览器中请求时,

( source ) 正确呈现,如

This is a header
See this is just like most other HTML

但是,当我尝试将 Python 代码嵌入到 .aspx 页面中时,如下所示:

<%@ Page Language = "Python" %>
<%
  Response.Write("Python lives in the ASP delimeters!")
%>
<br />

<script language="Python">
document.write("Python's throwing a party on the client-side!")
</script>
<br />

<script language="Python" runat="server">
 Response.Write("Python gets ready to rumble inside a server-side scripting block!")
</script>

( source ) 我收到以下错误:

error page

(请注意,我已在示例代码的第一行中添加了“Page” - 我已经尝试过使用和不使用它,两次都得到相同的错误)

看来我需要将 Python 注册为在 .aspx 文件中使用的语言。有人对我可能缺少的东西有什么建议吗?我按照上面第一个链接中的所有步骤进行操作(尽管我使用了 ActivePython 而不是 CPython),这使我进入了 .py 文件正确渲染的阶段,但遗憾的是这个(本来很好的)答案到此为止。

我运行了 C:\Python27\Lib\site-packages\win32comext\axscript\client\pyscript.py,输出“Registered: Python”,但是 C:\Python27\Lib\site-packages\win32comext\axscript\Demos\client\asp\tut1.asp 呈现为空白页面,而不是我期望从源代码中看到的 5 个越来越大的“Hello World”。我看到一个推荐here在 Debug模式下运行 pyscript,但我找不到如何查看输出。

我还查看了 this page在 Microsoft 知识库中,这似乎有些过时 - 例如,一些选项/选择的描述已更改名称或位置。

编辑:我看到了一些建议(底部的 herehere )声称问题出在最新版本的 ActivePython 上。我及时卸载了 ActivePython,下载了 CPython 2.7 和 Win32 扩展,并再次完成了整个过程,得到了相同的结果 - .py 文件正确渲染,但尝试在 .aspx 文件中使用 Python 会出现错误“Python 不是支持的语言”。

最佳答案

我很确定你做不到。 aspx 页面是编译到.NET 程序集中的 ASP.NET 页面。某处有一个 ASP.NET 编译器,在页面运行之前对其进行编译,并且它仅支持 .NET 语言...更糟糕的是它仅支持 C# 和 VB.NET(不支持 IronPython、F# 等)。

我假设您认为这是可能的,因为在旧的 ASP Classic 中可能(只是可能因为我不知道)语言是可插入的,但 ASP.NET 的情况并非如此,是完全不同的技术,唯一的共同点是名称中的字母“ASP”。

关于asp.net - 在 IIS 中的 .aspx 页面中使用 Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10567676/

相关文章:

python - 哪个 Python 最接近 Perl::Tidy?

python - 构建 python 时裤子因 scala 相关错误而失败

iis - 使用 WiX,如何更改虚拟目录的子文件夹的属性?

asp.net - 在我的IIS中部署两个网站并使用我的机器名访问

c# - 加密 SQL 连接字符串

asp.net - Windows Azure 网站上的主机文件

javascript - 客户端文件大小结束格式验证。为什么 JS 会阻止文件上传?

asp.net - Azure 中的后台任务

python - "from __builtin__ import True"的目的是什么?

IIS 7 - 虚拟目录重定向路径?