Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 479
  • Last Modified:

Redirect user to a login page from a handler

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
andre72
Asked:
andre72
  • 8
  • 6
1 Solution
 
tan_devCommented:
FormsAuthentication.SignOut();
Response.Redirect("~/Login.aspx");
0
 
Alpesh PatelAssistant ConsultantCommented:
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
 
tan_devCommented:
true. sorry i did just assume!
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
andre72Author Commented:
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
 
tan_devCommented:
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
 
tan_devCommented:
0
 
andre72Author Commented:
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
 
tan_devCommented:
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
 
andre72Author Commented:
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
 
tan_devCommented:
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
 
andre72Author Commented:
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
 
tan_devCommented:
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
 
andre72Author Commented:
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
 
tan_devCommented:
i found a good article:

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

hope this helps
0
 
andre72Author Commented:
Thanks I'll try it out and else I'll start a new thread ...
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

  • 8
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now