Redirect to corresponding page after LogINhttp://forums.asp.net/t/1787768.aspx/1?Redirect+to+corresponding+page+after+LogINFri, 06 Apr 2012 16:41:31 -040017877684910116http://forums.asp.net/p/1787768/4910116.aspx/1?Redirect+to+corresponding+page+after+LogINRedirect to corresponding page after LogIN <p>Hello all,</p> <p>How to redirect to corresponding page after login ???</p> <p>I mean that if some1 tries to open page Report.aspx but bcz of login security, he gets page of login.</p> <p>After successful login, I want to redirect the page Report.aspx...</p> 2012-04-01T06:16:17-04:004910149http://forums.asp.net/p/1787768/4910149.aspx/1?Re+Redirect+to+corresponding+page+after+LogINRe: Redirect to corresponding page after LogIN <p>hi,</p> <p>Are you using login control or textboxes for logging in? If you are using login control, then there will be a property &quot;<a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.login.destinationpageurl.aspx">DestinationPageUrl</a>&quot;, which you can set to the aspx page that you want to show after successful login</p> 2012-04-01T07:09:34-04:004910154http://forums.asp.net/p/1787768/4910154.aspx/1?Re+Redirect+to+corresponding+page+after+LogINRe: Redirect to corresponding page after LogIN <p>Login.aspx page code</p> <p>Private Sub buttonLogin_Click (ByVal sender as object, ByVal e as system.eventargs) handles buttonLogin.Click</p> <p>if textboxUserName.text = &quot;admin&quot; and textboxPassword.text = &quot;password&quot; then</p> <p>Session(&quot;IsAuthenticated&quot;) = true</p> <p>End If</p> <p>End Sub</p> <p>&nbsp;</p> <p>Report.aspx page</p> <p>&nbsp;</p> <p>Private Sub Page_Load (Byval sender as object, Byval e as System.EventArgs) Handles Me.Load</p> <p>if Session(&quot;IsAuthenticated&quot;) Is Nothing&nbsp;or Session(&quot;IsAuthenticated&quot;) &lt;&gt; true then</p> <p>Response.redirect(&quot;~/Login.aspx&quot;, true)</p> <p>End if</p> <p>End Sub</p> 2012-04-01T07:16:24-04:004910225http://forums.asp.net/p/1787768/4910225.aspx/1?Re+Redirect+to+corresponding+page+after+LogINRe: Redirect to corresponding page after LogIN <p></p> <blockquote><span class="icon-blockquote"></span> <h4>ramesh866</h4> re you using login control or textboxes for logging in? If you are using login control, then there will be a property &quot;<a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.login.destinationpageurl.aspx">DestinationPageUrl</a>&quot;, which you can set to the aspx page that you want to show after successful login</blockquote> <p></p> <p>I have used textboxes for login...</p> <p>after successfull login, user redirects on add.aspx page but what if he tries to open any page in betwn &amp; then after login ???</p> <p></p> 2012-04-01T08:56:39-04:004910243http://forums.asp.net/p/1787768/4910243.aspx/1?Re+Redirect+to+corresponding+page+after+LogINRe: Redirect to corresponding page after LogIN <p>Use&nbsp;<span>System.Web.Mvc</span><span>.</span><span>AuthorizeAttribute on your controller actions. It will redirect unauthenticated users to login page with ReturnUrl query string. User this query string to redirect users back to intended page after successful login.</span></p> 2012-04-01T09:31:04-04:004910257http://forums.asp.net/p/1787768/4910257.aspx/1?Re+Redirect+to+corresponding+page+after+LogINRe: Redirect to corresponding page after LogIN <p></p> <blockquote><span class="icon-blockquote"></span> <h4>tdesai</h4> Use&nbsp;<span>System.Web.Mvc</span><span>.</span><span>AuthorizeAttribute on your controller actions.</span></blockquote> <p></p> <p>Sorry, I didn't see properly. I thought you are using ASP.NET MVC</p> <p>If you are using some custom logic for authenticating and redirecting user to login page. You can add original url in query string while redirecting to login page and redirect back to that page on successful login.</p> 2012-04-01T09:50:37-04:004910307http://forums.asp.net/p/1787768/4910307.aspx/1?Re+Redirect+to+corresponding+page+after+LogINRe: Redirect to corresponding page after LogIN <p>if you want to restrict users to certain pages based on their role(if any) then use membership. i am not able to get what you are trying to achieve. :(&nbsp;</p> 2012-04-01T10:34:57-04:004910406http://forums.asp.net/p/1787768/4910406.aspx/1?Re+Redirect+to+corresponding+page+after+LogINRe: Redirect to corresponding page after LogIN <p>If you are using a session, u can check the session whether it is a null value using if loop..</p> <p>if it is null then, redirect to login page..</p> 2012-04-01T13:13:31-04:004914999http://forums.asp.net/p/1787768/4914999.aspx/1?Re+Redirect+to+corresponding+page+after+LogINRe: Redirect to corresponding page after LogIN <p></p> <blockquote><span class="icon-blockquote"></span> <h4>ramesh866</h4> if you want to restrict users to certain pages based on their role(if any) then use membership. i am not able to get what you are trying to achieve. :(&nbsp;</blockquote> <p></p> <p>I am using textboxes control for login &amp; I am using session...</p> <p><strong>I have 3 pages which are report.aspx, add.aspx, user.aspx...</strong></p> <p><strong>After login, I redirect user to user.aspx Page...</strong></p> <p><strong>Now i have nt login &amp; im trying to open page report.aspx but im not login so of course, it will redirect me on login.aspx page.</strong></p> <p><strong>but after i login, i want the website to redirect me on report.aspx page...</strong></p> <p>I have u understood my problem ???</p> <p></p> 2012-04-04T04:32:03-04:004915128http://forums.asp.net/p/1787768/4915128.aspx/1?Re+Redirect+to+corresponding+page+after+LogINRe: Redirect to corresponding page after LogIN <p></p> <blockquote><span class="icon-blockquote"></span> <h4>jeeten09</h4> <p></p> <p><strong>Now i have nt login &amp; im trying to open page report.aspx but im not login so of course, it will redirect me on login.aspx page.</strong></p> <p><strong>but after i login, i want the website to redirect me on report.aspx page...</strong></p> <p></p> </blockquote> <p></p> <p>As I said earlier, when you redirect not-loggedin user from Reports.aspx to Login.aspx, pass the url of report.aspx as a query string to login.aspx. After user logs in, check if there any url in query string. If yes, redirect user back to that url. In this case it's reports.aspx.</p> <p></p> <p>Hope this clears your doubt.</p> 2012-04-04T06:03:40-04:004916405http://forums.asp.net/p/1787768/4916405.aspx/1?Re+Redirect+to+corresponding+page+after+LogINRe: Redirect to corresponding page after LogIN <p></p> <blockquote><span class="icon-blockquote"></span> <h4>tdesai</h4> As I said earlier, when you redirect not-loggedin user from Reports.aspx to Login.aspx, pass the url of report.aspx as a query string to login.aspx. After user logs in, check if there any url in query string. If yes, redirect user back to that url. In this case it's reports.aspx.</blockquote> <p></p> <p>how to pass or check that url as a query string ???</p> <p></p> 2012-04-04T17:09:56-04:004917129http://forums.asp.net/p/1787768/4917129.aspx/1?Re+Redirect+to+corresponding+page+after+LogINRe: Redirect to corresponding page after LogIN <p></p> <blockquote><span class="icon-blockquote"></span> <h4>jeeten09</h4> how to pass or check that url as a query string ???</blockquote> <p></p> <p>In Reports.aspx:</p> <pre class="prettyprint">if(!IsLoggedIn) //Code to perform a check if a user is logged-in or not. { Response.Redirect(&quot;Login.aspx?ReturnUrl=&quot; &#43; Request.Url.AbsoluteUri); }</pre> <p>In Login.aspx:</p> <pre class="prettyprint">//ToDo: Validate username &amp; password //if ReturnUrl exist in query string, redirect user to ReturnUrl page. Else, redirect user to default (home) page. if(!string.IsNullOrEmpty(Request.QueryString["ReturnUrl"])) { string returnUrl = Request.QueryString["ReturnUrl"]; Response.Redirect(returnUrl); } else { Response.Redirect("Home.aspx"); } </pre> <p><br> <br> </p> <p><br> <br> </p> <p></p> 2012-04-05T05:12:29-04:004918243http://forums.asp.net/p/1787768/4918243.aspx/1?Re+Redirect+to+corresponding+page+after+LogINRe: Redirect to corresponding page after LogIN <p></p> <blockquote><span class="icon-blockquote"></span> <h4>tdesai</h4> <p></p> <p>In Reports.aspx:</p> <pre class="prettyprint">if(!IsLoggedIn) //Code to perform a check if a user is logged-in or not. { Response.Redirect(&quot;Login.aspx?ReturnUrl=&quot; &#43; Request.Url.AbsoluteUri); }</pre> <p>In Login.aspx:</p> <pre class="prettyprint"><span class="com">//ToDo: Validate username &amp; password</span><span class="pln"><br /><br /></span><span class="com">//if ReturnUrl exist in query string, redirect user to ReturnUrl page. Else, redirect user to default (home) page. </span><span class="pln"><br /></span><span class="kwd">if</span><span class="pun">(!</span><span class="kwd">string</span><span class="pun">.</span><span class="typ">IsNullOrEmpty</span><span class="pun">(</span><span class="typ">Request</span><span class="pun">.</span><span class="typ">QueryString</span><span class="pun">[</span><span class="str">"ReturnUrl"</span><span class="pun">]))</span><span class="pln"><br /></span><span class="pun">{</span><span class="pln"><br />&nbsp; &nbsp; </span><span class="kwd">string</span><span class="pln"> returnUrl </span><span class="pun">=</span><span class="pln"> </span><span class="typ">Request</span><span class="pun">.</span><span class="typ">QueryString</span><span class="pun">[</span><span class="str">"ReturnUrl"</span><span class="pun">];</span><span class="pln"><br />&nbsp; &nbsp; </span><span class="typ">Response</span><span class="pun">.</span><span class="typ">Redirect</span><span class="pun">(</span><span class="pln">returnUrl</span><span class="pun">);</span><span class="pln"><br /></span><span class="pun">}</span><span class="pln"><br /></span><span class="kwd">else</span><span class="pln"><br /></span><span class="pun">{</span><span class="pln"><br />&nbsp; &nbsp; </span><span class="typ">Response</span><span class="pun">.</span><span class="typ">Redirect</span><span class="pun">(</span><span class="str">"Home.aspx"</span><span class="pun">);</span><span class="pln"><br /></span><span class="pun">}</span></pre> <p></p> </blockquote> <p></p> <p>Hey, I m getting error...</p> <p>can u tell me more clearly abt it ???</p> <p></p> 2012-04-05T14:13:42-04:004918857http://forums.asp.net/p/1787768/4918857.aspx/1?Re+Redirect+to+corresponding+page+after+LogINRe: Redirect to corresponding page after LogIN <p>Use &nbsp;FormsAuthentication.RedirectFromLogingPage method...</p> <p><a href="http://msdn.microsoft.com/en-us/library/ka5ffkce.aspx">http://msdn.microsoft.com/en-us/library/ka5ffkce.aspx</a></p> 2012-04-06T03:50:03-04:004918964http://forums.asp.net/p/1787768/4918964.aspx/1?Re+Redirect+to+corresponding+page+after+LogINRe: Redirect to corresponding page after LogIN <p></p> <blockquote><span class="icon-blockquote"></span> <h4>jeeten09</h4> <p></p> <p>Hey, I m getting error...</p> <p>can u tell me more clearly abt it ???</p> <p></p> </blockquote> <p></p> <p>What error are you gettin? Could you please share your code?&nbsp;</p> 2012-04-06T06:08:11-04:004919610http://forums.asp.net/p/1787768/4919610.aspx/1?Re+Redirect+to+corresponding+page+after+LogINRe: Redirect to corresponding page after LogIN <p>This is code on <strong>Master Page</strong> :::</p> <pre class="prettyprint">protected void Page_Load(object sender, EventArgs e) { if ((Session[&quot;id&quot;] == null) &amp;&amp; (Session[&quot;role&quot;] != &quot;User&quot;)) { Response.Redirect(&quot;Login.aspx&quot;); } }</pre> <p><strong>Login Page</strong> :::</p> <pre class="prettyprint">protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Request.Cookies["Email"] != null) txtEmail.Text = Request.Cookies["Email"].Value; if (Request.Cookies["Password"] != null) txtPassword.Text = Request.Cookies["Password"].Value; if (Request.Cookies["Email"] != null &amp;&amp; Request.Cookies["Password"] != null) chkRemember.Checked = false; } } protected void btnLogin_Click(object sender, EventArgs e) { string str; str = "select * from tblUsers where Email = '" + txtEmail.Text + "' and Password = '" + txtPassword.Text + "' ; dt = objcon.ReturnDataTable(str); if (dt.Rows.Count &gt; 0) { Role_Type = (dt.Rows[0]["Role_Type"]).ToString(); Session["id"] = txtEmail.Text.Trim(); Session["role"] = dt.Rows[0]["Role_Type"].ToString(); } if (Role_Type == "User") { Response.Redirect("Report.aspx"); } else { lblNote.Visible = true; txtEmail.Text = ""; txtPassword.Text = ""; } }</pre> 2012-04-06T12:40:49-04:004919960http://forums.asp.net/p/1787768/4919960.aspx/1?Re+Redirect+to+corresponding+page+after+LogINRe: Redirect to corresponding page after LogIN <p></p> <pre class="prettyprint">protected void Page_Load(object sender, EventArgs e) { if ((Session[&quot;id&quot;] == null) &amp;&amp; (Session[&quot;role&quot;] != &quot;User&quot;)) { Response.Redirect(&quot;Login.aspx?ReturnUrl=&quot; &#43; Request.Url.AbsoluteUri); } }</pre> <p><br /><br /></p> <pre class="prettyprint">protected void btnLogin_Click(object sender, EventArgs e) { string str; str = "select * from tblUsers where Email = '" + txtEmail.Text + "' and Password = '" + txtPassword.Text + "' ; dt = objcon.ReturnDataTable(str); if (dt.Rows.Count &gt; 0) { Role_Type = (dt.Rows[0]["Role_Type"]).ToString(); Session["id"] = txtEmail.Text.Trim(); Session["role"] = dt.Rows[0]["Role_Type"].ToString(); } if (Role_Type == "User") { if(!string.IsNullOrEmpty(Request.QueryString["ReturnUrl"])) { string returnUrl = Request.QueryString["ReturnUrl"]; Response.Redirect(returnUrl); } else { Response.Redirect("Home.aspx"); //ToDo: Update your home page } } else { lblNote.Visible = true; txtEmail.Text = ""; txtPassword.Text = ""; } }</pre> <p><br> <br> </p> 2012-04-06T16:41:31-04:00