Advanced ASP.NET MVC Routing Script

I have an ASP.NET MVC application with the following deployment requirements:

The URL structure should be something like this:

http: // server / app / [enterprise] / [communinty] / {controller} / {action} / ...

What I want to be able to do is intercept the URL before the MVC route handler crashes on it, remove the [enterprise] / [community] parts, and then allow the MVC to continue processing as if the original URL did not contain these two segments.

That's why:

The application provides several portals to several clients (enterprises), and each community in the enterprise has its own user population. Such a scheme can also be served by physically deploying one instance of the application (binaries, content, web.config) in each [community] directory, but for logistic and performance reasons, I don’t think we want to go that route. So I'm trying to virtualize it with routing tricks.

Any suggestions on how to follow this pattern, or alternative solutions, will be appreciated.

We are on IIS 7, if that matters.

0
source share
2 answers

routes.MapRoute(
    null,
    "{enterprise}/{community}/{controller}/{action}/{id}",
    new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);

{enterprise} {community} .

+1

IIS. , . / MVC? . .

http://server.com/app/enterprise/community/controller/action/".

:

web.config IIS:

<rewrite>
    <rules>
        <clear />

        <rule name="Redirect to remove Offending String" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
            <match url="server.com/app/enterprise/community*" />
            <action type="Redirect" url="/{R:1}" />
            <conditions logicalGrouping="MatchAll">
                <add input="{SERVER_NAME}" pattern="*server.com*" />
            </conditions>
        </rule>

        <rule name="Rewrite to get Original Content" enabled="true" patternSyntax="Wildcard" stopProcessing="false">
            <match url="*" />
            <conditions logicalGrouping="MatchAll">
                <add input="{SERVER_NAME}" pattern="*server.com*" />
            </conditions>
            <action type="Rewrite" url="app/enterprise/community{R:1}" />
        </rule>

    </rules>
</rewrite>

. , .

0

Source: https://habr.com/ru/post/1756253/


All Articles