How to override/change FormsAuthentication LoginUrl in certain cases

前端 未结 3 576
孤城傲影
孤城傲影 2020-12-06 16:23

Is there a way to dynamically change the LoginUrl of FormsAuthentication? What I have is the whole site protected by FormsAuth, but for some pages in a sub folder, I\'d lik

3条回答
  •  半阙折子戏
    2020-12-06 17:07

    The problem you're having is that the Forms element is only allowed at the application level - you can't define it in a sub-web.config.

    Unfortunately you also can't define it using a Location element, and the FormsAuthentication.LoginUrl property is read only.

    Hunting around a bit, it looks like your best bet would be to have some code on your login page that detects where the user has arrived from (i.e. by checking the value of the "ReturnUrl" query string) and redirecting to your other login page if they are from the subdirectory. However I admit that this doesn't scale well at all if you want custom login pages for multiple sub-directories. :(


    In repsonse to your edit - yes, making the sub-folder an application would "solve" this error, but as you point out, you'd then have more problems, as you'd need to move all the relevant binaries, app_code, what have you into that sub-folder as well, so it's not really a solution.

提交回复
热议问题