开发者

Two pages using the same url depending on login status

开发者 https://www.devze.com 2023-01-25 13:22 出处:网络
What I would like to accomplish is: when user goes to www.mysite.com, then depending on whether he is logged in or not, he would see either login page or his home page. I do not want to redirect to ot

What I would like to accomplish is: when user goes to www.mysite.com, then depending on whether he is logged in or not, he would see either login page or his home page. I do not want to redirect to other pages, I want the url to show as www.mysite.com in bo开发者_如何学JAVAth cases. Kind of like when you go to facebook.com, it will either show you login page or your wall, all with the same url.

Any ideas?


If you are using ASP.NET WebForms (you didn't say) then you can use Server.Transfer in your home page to render the "login" page instead, if you detect the user is not logged in.

If you are using ASP.NET MVC, then your home page controller can check whether you're logged in or not and render the "login" view instead of whatever the default is.

Otherwise, if you want to use ASP.NET routing, you could do it with a custom route contraint. So you'd have two routes that match "/" but one has a custom constraint that checks whether the user is logged in or not.

0

精彩评论

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