ASP.NET 的通配符映射和 PHP 问题

发布于 2024-08-13 17:14:51 字数 443 浏览 10 评论 0原文

我有一个用 .NET 3.5 使用 C# 作为语言编写的应用程序。我正在使用 Web 表单,但使用 url 路由以及全局文件中定义的路由。一切都按预期进行。为了使漂亮的路径(请参阅:user/665 而不是 user.aspx?uid=665)正常工作,我必须在 IIS5.1(本地框,而不是测试、登台或生产)中添加通配符映射2.0 框架的 aspnet_isapi 文件。一切正常。

现在,我的网站需要一个 PHP 插件。但是,由于通配符映射,PHP 文件现在由 ASP.NET 提供服务,因此不会由 PHP 解释器处理。有什么办法可以解决这个问题吗?我是否必须向我的 Web 应用程序添加某种处理程序,以接受 ASP.NET 框架处理的所有 PHP 请求并将它们路由到 PHP 引擎?有更简单的方法吗?也许有一种方法可以将它们排除在 web.config (PHP 文件)中并让它们由适当的 PHP 引擎提供服务?

谢谢大家! -史蒂夫

I have an application written in .NET 3.5 with C# as the language. I'm using Web Forms, but using url routing with the routes defined in my global file. Everything is working as expected. In order for the pretty paths (see: user/665 instead of user.aspx?uid=665) to work properly, I had to add a wildcard mapping in IIS5.1 (local box, not test, staging, or production) the aspnet_isapi file for the 2.0 framework. Everything works fine.

Now, my site needs a plugin for PHP. However, the PHP files are now being serviced by ASP.NET due to the wild card mapping, and hence are not processed by the PHP interpretter. Is there any way to get around this? Would I have to add some sort of handler to my web app that will take all PHP requests being handled by the ASP.NET framework and have them routed to the PHP engine? Is there an easier way? Maybe a way to exclude them in the web.config (PHP files) and have them served by the proper PHP engine?

Thanks all!
-Steve

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

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

发布评论

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

评论(3

維他命╮ 2024-08-20 17:14:51

这是一个解决方案,但不是一个优雅的方法(恕我直言):

  1. 创建一个虚拟目录
  2. 让它指向包含文件的文件夹(在本例中是 PHP 插件)
  3. 赋予它适当的权限
  4. 更改虚拟目录的配置选项在 IIS 中并确保删除该目录的通配符映射。

这对我的情况来说就像一个魅力。但是,有什么办法可以不必处理虚拟目录呢?

This is a solution, but is not an elegant way (IMHO):

  1. Create a virtual directory
  2. Have it point to the folder with the files (in this case, a PHP plugin)
  3. Give it the proper permissions
  4. Change the config options for the virtual directory in IIS and make sure the wildcard mapping for that directory is removed.

This works like a charm for my situation. However, is there any way to not have to deal with virtual directories?

一抹淡然 2024-08-20 17:14:51

问题是PHP扩展需要注册。

  1. 在 IIS 管理器中右键单击默认网站 ->属性->主目录 -> 应用程序映射下的配置
  2. 确保添加了 .php 并且它是否指向 PHP.EXE。应该有这样的条目:扩展名 .php,可执行路径 C:\PHP\PHP.EXE %s %s

The problem is that the PHP extension needs to be registered.

  1. In IIS Manager right-click on Default Website -> Properties -> Home Directory -> Configuration
  2. Under Application Mappings make sure that .php is added and is it pointing to PHP.EXE. There should be an entry like this: extension .php, executable path C:\PHP\PHP.EXE %s %s
挽容 2024-08-20 17:14:51

据我所知,问题在于 ASP.NET 正在尝试路由您的 PHP 请求,因此我要做的就是将 StopRoutingHandler() 添加到 global.asax 中的路由中。像这样的东西应该有效:

routes.Add(new Route("{resource}.php/{*pathInfo}", new StopRoutingHandler()));

编辑:请注意路线是按顺序处理的,所以我会将其添加到路线的顶部。

From what I gather, the problem is that ASP.NET is attempting to route your PHP requests, so what I would do is add a StopRoutingHandler() to your routes in the global.asax. Something like this should work:

routes.Add(new Route("{resource}.php/{*pathInfo}", new StopRoutingHandler()));

Edit: Be mindful that routes are processed in order, so I would add this to the top of your routes.

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