Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Redirect user to a login page from a handler

Posted on 2010-11-10
15
Medium Priority
?
476 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 

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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

618 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