Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
When we copy the url from one browser window to another browser window the page for the specified url address should not be displayed it should be redirected to login page only.
Posted

C#
if (clsCommon.getCookieValue(clsCommon.AdminCookiesName.Admin_MUSRID.ToString()) != null)
        {
            if (string.IsNullOrEmpty(clsCommon.getCookieValue(clsCommon.AdminCookiesName.Admin_MUSRID.ToString())))
                Response.Redirect("login.aspx", true);
        }


or


XML
if ((Session["MCUSXintIde0"] + "") != "")
           {
           }
           else
           {
               Response.Write("<script type=\"text/javascript\">" +
                       "window.parent.location = '" + clsCommon.value("SiteUrl") + "login?loginUrl=' + window.parent.location + '';" +
                               "</script>");
               Response.End();
           }
 
Share this answer
 
You must specify the authentication and authorization tags in web.Config files to redirect to a loginpage if the user is anonymous.


ASP.NET authentication and authorization[^]
 
Share this answer
 
use following code
Place this code in ur web.config file
XML
<authentication mode="Forms">
      <forms loginUrl="~/Account/Login.aspx" timeout="2880" />
    </authentication>

login url is the relative address of ur login page.
 
Share this answer
 
Use "Asp.Net Session"

Have a look at this.
http://msdn.microsoft.com/en-us/library/ms178581.aspx

Updated -
This also seems to be useful for your requirement.
ASP.NET Login Controls Overview
 
Share this answer
 
v3
Comments
member60 1-Nov-11 6:13am    
but what if we are not using any Login controls?
member60 1-Nov-11 6:19am    
waiting for reply .
RaisKazi 1-Nov-11 8:00am    
Those are alternate options, it's depends with which you want to go.
Hi ,

Use Global Application Class( Global.asax)


<%@ Application Language="C#" %>

<script runat="server">

    void Application_Start(object sender, EventArgs e) 
    {
        // Code that runs on application startup
        

    }
    
    void Application_End(object sender, EventArgs e) 
    {
        //  Code that runs on application shutdown

    }
        
    void Application_Error(object sender, EventArgs e) 
    { 
        // Code that runs when an unhandled error occurs

    }

    void Session_Start(object sender, EventArgs e) 
    {
       
        Response.Redirect(Request.Url.GetLeftPart(UriPartial.Authority) + VirtualPathUtility.ToAbsolute("~\\LoginPage.aspx"));
        
        
        
    }

    void Session_End(object sender, EventArgs e) 
    {
        
        Response.Redirect(Request.Url.GetLeftPart(UriPartial.Authority) + VirtualPathUtility.ToAbsolute("~\\LoginPage.aspx"));
       
        // Code that runs when a session ends. 
        // Note: The Session_End event is raised only when the sessionstate mode
        // is set to InProc in the Web.config file. If session mode is set to StateServer 
        // or SQLServer, the event is not raised.

    }
       
</script>





When you copy the url from one browser window to another browser window the page will redirected to login page


Regards,
Pal
 
Share this answer
 

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