在WordPress网站上的.NET虚拟目录中,URL路由不起作用

时间:2018-12-03 01:10:47

标签: c# asp.net wordpress url-routing virtual-directory

可以说这是根网站,它是一个WordPress PHP网站:

www.mywebsite.com

我在根网站上将一个子文件夹制作成一个.NET App(一个有效的ASP.NET网站)

www.mywebsite.com/subapp

ASP.NET网站“ subapp”工作正常,但Web路由不起作用。

页面“〜/ Login.aspx”运行正常。此页面已路由到“〜/登录”,该页面可以作为根网站正常运行,但在虚拟目录中失败。

这有效:

www.mywebsite.com/subapp/Login.aspx

这不起作用:

www.mywebsite.com/subapp/Login

该路由由WordPress捕获,并通过wordpress显示“找不到页面”。

这是WordPress网站的web.config:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)"/>
<conditions><add input="{HTTPS}" pattern="off" ignoreCase="true"/></conditions>
<action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{R:1}"/>
</rule>
<rule name="WordPress: https://www.mywebsite.com" patternSyntax="Wildcard">
<match url="*"/>
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
</conditions>
<action type="Rewrite" url="index.php"/>
</rule></rules>
</rewrite>
</system.webServer>
</configuration>

这是“ subapp”的Web路由C#代码:

using System.Web.Routing;

public class Global : System.Web.HttpApplication
{
    protected void Application_Start(object sender, EventArgs e)
    {
        RouteTable.Routes.MapPageRoute("login", "Login", "~/Login.aspx");
    }
}

1 个答案:

答案 0 :(得分:0)

我已经通过删除WordPress网站上的web.config的“ URL重写规则”解决了这个问题。

这是修改后的web.config,可解决此问题:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)"/>
<conditions><add input="{HTTPS}" pattern="off" ignoreCase="true"/></conditions>
<action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{R:1}"/>
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

这是原始的web.config:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)"/>
<conditions><add input="{HTTPS}" pattern="off" ignoreCase="true"/></conditions>
<action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{R:1}"/>
</rule>
<rule name="WordPress: https://www.mywebsite.com" patternSyntax="Wildcard">
<match url="*"/>
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
</conditions>
<action type="Rewrite" url="index.php"/>
</rule></rules>
</rewrite>
</system.webServer>
</configuration>

但是,通过此编辑,WordPress无法捕获任何“找不到页面”错误。

以前,如果我在WordPress网站上输入随机URL,它将被捕获并显示漂亮的“找不到页面”页面,但只会返回服务器默认的404页面。