2

我遇到了一个问题(asp.net 3.5):当导航到https://mypage.net时,它会将我重定向到https://mypage.net/Login.aspx?ReturnUrl=%2f不允许登录(因为ReturnUrl=%2f)。

为了解决这个问题,我更改了 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");
    }

现在它似乎工作完美,但不是。

问题是我有另一个可以通过 https://mypage.net/QA访问的虚拟应用程序 如果我直接输入 https://mypage.net/QA/login.aspx那么一切都很好。

但是,如果我输入https://mypage.net/QA,则会显示“虚拟路径 '/Login.aspx' 映射到另一个应用程序,这是不允许的。”

你如何处理这个问题?

4

1 回答 1

0

也许做这样的事情来逻辑地路由事情而不是物理文件

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();
    }
于 2013-02-18T01:51:35.737 回答