Solved

Redirect user to a login page from a handler

Posted on 2010-11-10
15
464 Views
Last Modified: 2013-12-17
Hi,

I've some controls (AutoSuggest, TreeView) that get there data dynamic from a ajax callback from a handler.
Is there a way to redirect the user direct to a login page from server side when the session is lost?

When I try something like context.Response.Redirect() the login page will be the return code of the handler and this makes no sense for sure as the login page will than be only a node in the TreeView.

How to redirect the main content to a login page?

Thanks

andre
0
Comment
Question by:andre72
  • 8
  • 6
15 Comments
 
LVL 2

Expert Comment

by:tan_dev
Comment Utility
FormsAuthentication.SignOut();
Response.Redirect("~/Login.aspx");
0
 
LVL 21

Expert Comment

by:Alpesh Patel
Comment Utility
If Memnership then "tan_dev" is right. But custom method then clear the session variable and check for session variables value against your wish. IF value is not as per application then move to login page. else do nothing
0
 
LVL 2

Expert Comment

by:tan_dev
Comment Utility
true. sorry i did just assume!
0
 

Author Comment

by:andre72
Comment Utility
No, I'm sorry this is not my problem.
I need someting like:
if(Session["something"]== null) <a href="Login.aspx" target="_top">

When the session ends and you expand one more node the tree looks like this:

Site main.aspx:
root
|- node1
       |- subnode1
       |- subnode2
|- node2
       |-  Loginpage because of session expired
       |-  ...
       |-  ...
|- node3
|- node4

I want to change the whole site when session expired that main.aspx becomes Login.aspx
0
 
LVL 2

Expert Comment

by:tan_dev
Comment Utility
Initialise Session variable at Session_start in Global.asax

Session["ID"] = somevalue;            

In your code behind page for defining treeview:

If(Session["ID"]==null)
{
 TreeNode child = new TreeNode();
                child.NavigateUrl = "~/Login.aspx";
                child.Text = "Login";
                tvMenu.Nodes.Add(node);
                node.ChildNodes.Add(child);
//node is your parent treenode
}
0
 
LVL 2

Expert Comment

by:tan_dev
Comment Utility
0
 

Author Comment

by:andre72
Comment Utility
Do I unerstand you right that you suggest to let the user click at the node to redirect to the Login.aspx and the user need to click at the node?
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 2

Expert Comment

by:tan_dev
Comment Utility
yes user will still have to click.
are you trying to achieve something else?
havent you initialised your tree view in a similar way?
0
 

Author Comment

by:andre72
Comment Utility
I think my english is really to bad ...
The user should automatik redirected to the Login.aspx, eg:
User have lunch -> Session expired -> user come back to the pc -> user click a root node -> root node call handler for subnodes -> handler recognize that session is expired and automatic redirect user to Login.aspx -> user login again
0
 
LVL 2

Expert Comment

by:tan_dev
Comment Utility
why cant you put this entire page (with treeview) to be accessed by known users only:

Put this in Web.config
  <location path="FolderWithTreeView">
    <system.web>
      <authorization>
        <deny users="?"/>
      </authorization>
    </system.web>
  </location>
      
This way user is redirected to Login page automatically when authorization expires.
If I knew which part exactly you're stuck at might have been able to help more. maybe put up your cod of what you already have.
0
 

Author Comment

by:andre72
Comment Utility
I agree this will be a great solution as in this case any call to any handler/page will redirect than to the login page.
The matter is that I not very familar with the web.config and if I understand your suggestion right also the Login.aspx will be protected right?
In this case no user can login, can he?
0
 
LVL 2

Expert Comment

by:tan_dev
Comment Utility
in your <system.net> put the code above
the <location path="FolderWithTreeView"> specifies the folder which needs to be protected.
As long as you Login.aspx is not in that folder it will be accessible by everyone.
ideally you should put your login page in the root folder of project/ app.

Think you should try picking up little bits of web.config since it might help quite a few problems.

you can even set your login page and session details in web.config. just put it under
<system.web> </system.web> (just above system.net tag)

   <authentication mode="Forms">
      <forms name="AppName"
             loginUrl="~/Login.aspx"
             slidingExpiration="true"
          defaultUrl="Default.aspx"
          cookieless="UseCookies"
          enableCrossAppRedirects="false"
           timeout="1080"  />
    </authentication>
0
 

Author Comment

by:andre72
Comment Utility
I can't make it work ...
Maybe you know a page where I can read all necessary steps for ...?

  <authentication mode="Forms">
    <forms name="AppName"
           loginUrl="~/Default.aspx"
           slidingExpiration="true"
        defaultUrl="main.aspx"
        cookieless="UseCookies"
        enableCrossAppRedirects="false"
         timeout="1080"  />
  </authentication>

As you see the problem with my autosuggest is the same ...
Suggest.gif
0
 
LVL 2

Accepted Solution

by:
tan_dev earned 500 total points
Comment Utility
i found a good article:

http://support.microsoft.com/kb/316871

hope this helps
0
 

Author Closing Comment

by:andre72
Comment Utility
Thanks I'll try it out and else I'll start a new thread ...
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now