简体   繁体   中英

Mvc start page using areas on azure with domain

I have an mvc web app that uses areas. On my developer machine the website starts up with the correct page. In my vs studio in the settings I have set the start action to my area. I am having trouble getting this to work on azure.

The starting area is authentication.

On azure I have a custom domain, lets call it "mydomain.co.za". When I call up the domain, it says "The resource cannot be found."

I have to call "mydomain.co.za/authentication".

I need it to route to the authentication by just using mydomain.co.za Is there specific config needed in the web config? Please assist.

I think it can be achieved with the rewrite rule, however, I am struggling to fit this in.

Currently I have a rule to convert from http to https, but not sure where to fit the area in

<directoryBrowse enabled="false" />
        <httpRedirect enabled="false" destination="https://mydomain.co.za" exactDestination="true" />
        <rewrite>
            <rules>
                <rule name="http to https" enabled="true" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{HTTPS}" pattern="^OFF$" />
                    </conditions>
                    <action type="Redirect" url="https://www.mydomain.co.za/{R:1}" redirectType="SeeOther" />
                </rule>
            </rules>
        </rewrite>

I am quite new to azure so I am also not sure if this needs to be done in the web config, or if I can configure it in the azure web app settings?

After reading your description, I concluded that what you want is the page A.cshtml in Areas as the starting page. The Startup Page in the Areas area requires authentication. If no verification is passed, go to authentication.cshtml for login verification.

If there is no error in my summary, the point you need to pay attention to is not rewrite . It should be the actual routing configuration . I will show the screenshot below for the specific operation steps. All have been deployed to azure for testing, and the test passed without problems.

You can download my demo for test .

RouteConfig.cs

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        var route = routes.MapRoute("Default", "{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional },
            namespaces: new[] { "areaproj.Areas.Admin.Controllers" }
        );
        route.DataTokens["area"] = "Admin";
    }

Areas/Admin/Views/Home/Index.cshtml (startup page)

    public ActionResult Index()
    {
        bool IsAuth = false;
        if (IsAuth)
            return View();
        else
            return View("~/Areas/Admin/Views/Home/test.cshtml");
    }

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM