Answered by:
User.Identity.IsAuthenticated Problem

Question
-
User2033107836 posted
Hi
This is my code on page Load of A.aspx
if (User.Identity.IsAuthenticated == false) { Server.Transfer("login.aspx"); }
When user vists without login it will redirect to login.aspx page
after entering username and password why its not redirecting to A.aspx page..?
Thursday, November 10, 2016 4:41 PM
Answers
-
User-271186128 posted
Hi asp.ambur,
When user vists without login it will redirect to login.aspx page
after entering username and password why its not redirecting to A.aspx page..?
As for this issue you could transfer the returnUrl as parameters, you can refer to the following code:
public ActionResult Login(string returnUrl) { ViewBag.ReturnUrl = returnUrl; return View(); } // // POST: /Account/Login [HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public async Task<ActionResult> Login(LoginViewModel model, string returnUrl) {
//...
return View()
}Then, if login success, you could redirect to the returnUrl.
Best regards,
Dillion- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, November 11, 2016 6:56 AM
All replies
-
User-691209617 posted
Hi
It seems like you are using identity of Asp.Net if yes then can you share, how you implement identity and secondly which application you used web forms or MVC.
Thursday, November 10, 2016 4:52 PM -
User753101303 posted
Hi,
You don't have done anything for this to happen or show us the code (also keep in mind "redirect" happens on the client side while "transfer" happens on the server side).
Might be also a confusion with what ASP.NET does out of the box for you (it keeps the targeted page using a ReturnUrl parameter which is then use to direct the user there once logged (or on a default page otherwise)).
I would suggest to juse use what ASP.NET offers out of the box rather else you have to reimplement yourself this mechanism. Try perhaps https://msdn.microsoft.com/en-us/library/7t6b43z4.aspx for a start...
Thursday, November 10, 2016 5:05 PM -
User-271186128 posted
Hi asp.ambur,
When user vists without login it will redirect to login.aspx page
after entering username and password why its not redirecting to A.aspx page..?
As for this issue you could transfer the returnUrl as parameters, you can refer to the following code:
public ActionResult Login(string returnUrl) { ViewBag.ReturnUrl = returnUrl; return View(); } // // POST: /Account/Login [HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public async Task<ActionResult> Login(LoginViewModel model, string returnUrl) {
//...
return View()
}Then, if login success, you could redirect to the returnUrl.
Best regards,
Dillion- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, November 11, 2016 6:56 AM