Solved

Redirect user to a login page from a handler

Posted on 2010-11-10
15
466 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
 

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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

920 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

16 Experts available now in Live!

Get 1:1 Help Now