开发者

Problem with LogOn page loading inside div on membership redirection

I am using Membership Authentication in an MVC3 webapp. I make heavy use of jQuery and loading partial views inside divs and tabs. My problem is when the user has been inactive and is logged out and then he tries to call an Action inside a Controller which loads a partial view inside a div or tab, the entire page with the LogOn view is loaded inside the div, wrecking my layout.

The redirection is done correctly, and is the desired effect, however I would like the LogOn page to load on the window, rather than on a div in the current view. Does anyone knows how to accomplish this?

Is it clear what I want and w开发者_运维技巧hats wrong?

Thank you.


The combination of authenticated calls and Ajax is always a problem, because Ajax doesn't properly handle the redirect.

I prefer not to the the Authorize attribute on Ajax-called controller actions, but to check for the user being authenticated inside the method and returning a specific HTTP response (such as HTTP403 Unauthorised). Using an error handler in your client-side script, you can test for this response and redirect to the login page by setting window.location.


Just fixed my problem with a little script. Its not the best solution, and I am not totally comfortable with it, but at least it solves my problem in a very simple way.

In case anyone is interested, here its what I did, I added this snippet of code at the beginning of my Log on page:

<script type="text/javascript">

    function funcName() {
        var str = window.location.href;
        var num = loc.indexOf('@Url.Action("Action", "Controller", new { area = "" })');
        if (num < 0) {
            window.location = '@Url.Action("Action", "Controller", new { area = "" })';
        }
    }

    relocate();
</script>

This way if the login page loads inside some div and not on the window, it relocates to the actual login page.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜