Solved

Redirect user to a login page from a handler

Posted on 2010-11-10
15
468 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
ID: 34100745
FormsAuthentication.SignOut();
Response.Redirect("~/Login.aspx");
0
 
LVL 21

Expert Comment

by:Alpesh Patel
ID: 34101581
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
ID: 34101599
true. sorry i did just assume!
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:andre72
ID: 34102148
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
ID: 34102515
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
ID: 34102519
0
 

Author Comment

by:andre72
ID: 34102904
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
 
LVL 2

Expert Comment

by:tan_dev
ID: 34102941
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
ID: 34102976
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
ID: 34103091
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
ID: 34103393
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
ID: 34103531
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
ID: 34103949
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
ID: 34110029
i found a good article:

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

hope this helps
0
 

Author Closing Comment

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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

828 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