简体   繁体   中英

Forms Authentication The virtual path '/Login.aspx' maps to another application, which is not allowed

I had an issue (asp.net 3.5): when navigation to https://mypage.net it redirected me to https://mypage.net/Login.aspx?ReturnUrl=%2f which did't allow to login (because of ReturnUrl=%2f).

To solve this I have changed my global.aspx Application_BeginRequest:

     protected void Application_BeginRequest(object sender, EventArgs e)
    {
        // redirect user from http to https
        if (!Request.IsLocal && !Request.IsSecureConnection)
        {
            string redirectUrl = Request.Url.ToString().Replace("http:", "https:");
            Response.Redirect(redirectUrl);
        }

        // I HAVE ADDED THESE LINES!!!!!!!!!!!!!!
        if (Request.AppRelativen aCurrentExecutionFilePath == "~/")
            HttpContext.Current.RewritePath("Login.aspx");
    }

Now it seems to work perfect, but not.

THe problem is that I have another virtual application that is accessible via https://mypage.net/QA If I enter directly https://mypage.net/QA/login.aspx then everything is fine.

But if I enter https://mypage.net/QA then it says "The virtual path '/Login.aspx' maps to another application, which is not allowed."

How do you deal with this?

Maybe do something like this to route things logically rather than to physical files

http://msdn.microsoft.com/en-us/library/cc668201%28v=vs.100%29.aspx

    //-----------------------------------------------------------------------------------
    // Name:        RegisterRoutes
    // Purpose:     Register the routes for the site.
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("admin/errorlog.axd/{*pathInfo}");

        routes.MapRoute(
            "Base", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Base", action = "Main", id = UrlParameter.Optional }  // Parameter defaults
        );
    }


    //-----------------------------------------------------------------------------------
    // Name:        Application_Start
    // Purpose:     The application start event handler.
    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();

        RegisterGlobalFilters(GlobalFilters.Filters);
        RegisterRoutes(RouteTable.Routes);

        InitSquishIt();
    }

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