Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi..

In my MVC application I have the requirement to redirect to login page while user after logged in the application if he copy and paste the url in same browser and also in new tab..

I had successfully to redirect to login page if he paste in other browsers..

for that I wrote the code as follow in the Global.asax.cs file

C#
///added by honey..

        protected void Session_Start(Object sender, EventArgs e)
        {
            if (!Request.FilePath.Contains("Default"))
            {
                string strPreviousPage = "";

                if (Request.UrlReferrer != null)
                {
                    strPreviousPage = Request.UrlReferrer.Segments[Request.UrlReferrer.Segments.Length - 1];
                }
                if (strPreviousPage == "")
                {
                    HttpContext.Current.Session.Add("CurrentCompany", "Company 1");
                    var routeData = new RouteData();
                    routeData.Values["controller"] = "Account";
                    routeData.Values["action"] = "Login";
                    Response.StatusCode = 500;
                    IController controller = new HomeController();
                    var rc = new RequestContext(new HttpContextWrapper(Context), routeData);
                    controller.Execute(rc);
                }
            }
        }


For the same browser or in new tab in that browser, how i can accomplish the requirement..
if u know, help me..

Thanks ,
Honey.
Posted
Updated 24-Sep-14 0:58am
v3

1 solution

Please check this site[^]

But I am unsure, If this is possible.
Thanks :)
 
Share this answer
 
Comments
honey4bee 24-Sep-14 9:08am    
No... dts not my requirement..
i want to do in programmatically and also i need to restrict to open..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900