如何将对域的所有请求路由到子文件夹asp.net [英] How to route ALL requests for domain to a sub folder asp.net

查看:73
本文介绍了如何将对域的所有请求路由到子文件夹asp.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到很多解决方案,但是似乎没有一个....

I have seen lots of solutions to this but none seem to work....

我有一个域

producerpte.co.uk

但是我在子文件夹中设置了一个单独的应用程序,因此必须查看该应用程序的根目录...

But I have a separate application set up in a sub folder so to see the root of that application you have to go to...

producerpte.co.uk/producerpte

但是我想要这样做,以便用户看不到网址的"site1"部分.

However I want it so that the user does not see the 'site1' part of the url.

当我在Web.Server配置中使用url重写或在代码中(在根目录上设置的应用程序中)使用Context.RewritePath时,它只是将用户重定向到url(其中包含site1),我不希望用户知道他们要去一个子文件夹.

When I use url rewriting in Web.Server config or I use Context.RewritePath in code (in an application set up on the root) it simply redirects the user to the url (with site1 in it) I do not want the user to know they are going to a subfolder.

我设置错了吗?

我实际上正在使用Winhost.香港专业教育学院尝试过的所有示例都不会更改呼叫的结果,而无需重定向url:-(

I'm actually using Winhost. All the examples ive tried just do not change result of the call without redirecting the url :-(

winhost告诉我应该使用代码/配置来执行此操作.老实说,我更喜欢用代码来做....

I have been told by winhost that I should do it with code/configuration. I would prefer to do it with code to be honest....

更新:我尝试了麦克斯的答案,但是我做了...

UPDATE : I tried Max's answer and I did...

 <rules>
    <rule name="Redirect if producerpte" stopProcessing="true">
        <match url="^ producerpte/(.*)$" />
        <action type="Redirect" url="{R:1}" />
    </rule>
    <rule name="Rewrite to sub folder">
        <match url="^.*$" />
        <action type="Rewrite" url="producerpte/{R:0}" />
    </rule>
  </rules>

但是没有运气:-(而且网址仍然在浏览器中更改....

But no luck :-( And the urls still change in the browser....

推荐答案

如果WinHost确实启用了IIS Rewrite Module,请编辑您的web.config文件并尝试以下规则:

If WinHost did enable IIS Rewrite Module, edit your web.config file and give this rule a try:

<rewrite>
<rules>
    <rule name="Redirect if site1" stopProcessing="true">
        <match url="^site1/(.*)$" />
        <action type="Redirect" url="{R:1}" />
    </rule>
    <rule name="Rewrite to sub folder">
        <match url="^.*$" />
        <action type="Rewrite" url="site1/{R:0}" />
    </rule>
</rules>
</rewrite>

---更新---

好吧,我测试了此IIS配置:

Well, I tested this IIS configuration:

我已在 root 网站上添加了规则.
IIS创建了一个web.config文件:

I've added rules on the root site.
IIS created a web.config file:

这是web.config文件的内容:

Here's the content of the web.config file:

<configuration>
    <system.webServer>
        <rewrite>
             <rules>
                <rule name="Redirect if producerpte" stopProcessing="true">
                    <match url="^producerpte/(.*)$" />
                    <action type="Redirect" url="{R:1}" />
                </rule>
                <rule name="Rewrite to sub folder">
                    <match url="^.*$" />
                    <action type="Rewrite" url="producerpte/{R:0}" />
                </rule>
              </rules>
        </rewrite>
    </system.webServer>
</configuration>

  • http://localhost:8066/在不更改浏览器URL的情况下显示C:\inetpub\wwwroot\producerpte\producerpte的内容

    • http://localhost:8066/ displays the content of C:\inetpub\wwwroot\producerpte\producerpte without changing the URL in browser

      http://localhost:8066/producerpte/显示C:\inetpub\wwwroot\producerpte\producerpte的内容,但浏览器中的URL更改为http://localhost:8066/

      http://localhost:8066/producerpte/ displays the content of C:\inetpub\wwwroot\producerpte\producerpte but the URL in browser is changed to http://localhost:8066/

      请确保您在 root 站点(而不是子应用程序)上创建规则,并且我注意到您的配置中有一个前导空格:<match url="^ producerpte/(.*)$" />^.

      Be sure that you created rules on the root site (and not the sub application) and I noticed that you had a leading space in your config: <match url="^ producerpte/(.*)$" /> between ^ and producerpte.

      这篇关于如何将对域的所有请求路由到子文件夹asp.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆