How to store Requested Page url? - c#

By Default Person is Redirected to home page after logging in and if person request for any page without login, it will be automatically redirected to login page.
Now my question is that how to store the page url that the person requested without login so that it can be redirected to that page after it the proof of its authentication.

If you are using ASP.NET Forms Authentication, the module will pass teh initially requested page as query string parameter called ReturnUrl. This way when the user enters his credentials and if they are valid you could use this parameter to redirect him.

Related

Identityserver post login url should be last state before logout in .net core

By Default when we log in using identity server it goes to default page that is domain/signin-oidc and then to default screen.
but i want that after person logs in we can decide dynamically where do we want to send our customer.
Like their is possibility that you were working on one page x and you were logged out because of session expiration then you should again be redirected after login to the same page x. but in current time it is redirected to default page.

How to redirect to the URL entered after login

I'm working in a WEB project based on ASP.NET and C#. It's not a new project, I'm just fixing some bugs and making some updates.
The website works like, if you're not logged in and write a url depending on the website, it redirects you to the login page. Then, if you login successfully, it redirects you to the opening page.
For instance, let's say "opening.aspx" is the opening page and "vendors.aspx" is another page in the website. If you write "..../projectname/vendors.aspx" to the browser, you're redirected to "..../projectname/login.aspx", then after your login you're redirected to "..../projectname/opening.aspx"
Now, my aim is to redirect the user to the url he wrote, in this example "..../projectname/vendors.aspx" after the successful login. I wrote the code to take the previous page and after the login redirect the user to that page. However, I cannot detect the page which the user tried to enter at the first time. I'm not sure if the project sends the user to the login page with some codes written by the previous programmers or if this is an automatic stuff of asp.net about the default page. While debugging, I always see the requested page as the login page even though I write some other page url to the browser.
What I'm looking for is the place where the requested page is changed into login page instead of the url I wrote. Is this an automatic stuff or should I look for it in the code? If I should look for it in the code, where to look?
Note: The project is based on 3-Tier architecture, with WEB, BUS, DAL and COM layers and WEB pages use user controls in every page instead of login and default.
Typically when asp.net redirects it puts the requested page in the url in the ReturnUrl querystring parameter. You should be able to do something like...
if (Request.QueryString["ReturnUrl"] != null)
Response.Redirect(Request.QueryString["ReturnUrl"]);
If you need to do something special, you could store the original page that is in ReturnUrl in something like session or in the database and then redirect after your opening page or what not.
i think u should use cookies and seesion when user logged in user detail saved in cookies
and next time when user enter the url u can check it on masterpage of that pages that cookies are available or not if details available then shoe current url page otherwise redirect on login page

How to maintain URL that user entered

My iis folder structure is like
Default Web Site---->online and Accessing with www.sitename.com/online
Default Web Site---->trade and Accessing with www.sitename.com/trade
Default Web Site---->private and Accessing with www.sitename.com/private
Here the login page is residing inside "Default Web Site---->trade/Login.aspx".When user enter
www.sitename.com/online or www.sitename.com/private or www.sitename.com/trade he/she will be redirecting to the url www.sitename.com/trade/Login.aspx.
So my need is when user enter "www.sitename.com/online" he/she should remain in the same URL as www.sitename.com/online and not "www.sitename.com/trade/Login.aspx".So how can i maintain the URL that user entered.
Thanks,
Joby
Best way to do this is pass a parameter w/ original url in your redirect to login page, and then have login redirect you back to that original url
Location: http://example.com/login?ref=http%3A%2F%2Fexample.com%2Ffoo
Then after login, you read "ref" parameter and do a location redirect back.
If you are using built-in membership provider, then you may use [Authorize] attribute, that has an functionality to redirect the user to original page, after user gets authenticated system will automatically redirect the user to requested page.
Or you may try following solution:
Something like this:
www.sitename.com/trade/Login.aspx?ReturnUrl=http%3A%2F%2Fsitemap.com%2Fonline
After user gets authenticated, you may redirect the user to requested page.
Response.Redirect(Request.QueryString["ReturnUrl"]);
Consider using MVC or at least routing portion of it with ASPX pages to render views. This way you can have any Urls you want unrelated to physical file names.
Users rarely enter any urls... and I'm not really sure anyone cares as long as Url makes some sence (or complete noncense). So I think it is perfectly ok to render login page at something like /login and than redirect back to originating page. You can save original url in query string (as #chovy suggests) or hidden element on the page if login never leaves your site. If login leaves your site (i.e. for OAuth authentication) thatn session state or cookies may be place to store return Url.

How to choose landing page after user logs in?

I was wondering when a user logs in using the login control for ASP.NET, how do we choose where the user goes after? Do we configure this in the web.config file?
Generally, you go where the user asked to go.
What usually happens is that the user requests to go to a page which requires that he be authenticated. If he's not authenticated, he gets redirected to the login page. That page accepts username and password, and gets him authenticated. It then redirects him to the page he originally requested.
Users may get annoyed with you if they requested to go to page "A" and you send them to page "B".
If the user didn't request a particular page, then he will usually go to Default.aspx. At that point, you might choose a landing page for the user, in whatever manner you like, and redirect to that page.
You can use FormsAuthentication DefaultUrl property or forced redirect user with Response.Redirect(...) after he logged in.
Or just simply allow user continue with his initial request.

Maintain return URL in live id integration

I am creating an application in which I am using Live Id authentication. When the user tries to access an authenticated page, I am redirecting the user to Live Id sign in page. Is it possible to return the user to the previously asked page (from which he was redirected). Some thing like return URL.
Actually I want to pass some data in query string to webauth-handler.aspx page when the user successfully logs in. Can any body tell me how to pass query string to webauth-handler.aspx?
Thanks
Ashwani
When the user tries to acces a page that needs authenticated (prior to redirection) save the returnUrl to a Session Variable:
Session["MyReturnUrl"] = Request.QueryString["ReturnURL"];
You would have set up your Live Authentication Settings to always redirect to a certain page on your site if authentication is successfull, on that page you will simply do the following:
//Set Authentication cookie here then redirect to previously requested url
Response.Redirect(Session["MyReturnUrl"]);
I fixed this by saving the return url in cookie and then checking if the cookie is present to do the redirection.

Categories

Resources