Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

I have a problem with returnUrl for authentication

$
0
0

Hi,

I have a problem with returnUrl for authentication. I used returnUrl in my form 

<form id="profile-form" method="post" asp-controller="Account" asp-action="UserAccount"
    asp-route-returnUrl="@Html.Raw(Context.Request.Path)" ><button class="btn btn-primary" type="submit">Submit</button></form>

        [Authorize(Roles = "Admin, User")]
        [HttpPost]
        [ValidateAntiForgeryToken]
        public async Task<IActionResult> UserAccount(AccountModel model, string returnUrl)
        {
            return LocalRedirect(returnUrl);
        }
            services.ConfigureApplicationCookie(options =>
            {
                options.ExpireTimeSpan = TimeSpan.FromMinutes(10);
                // Cookie settings
                options.Cookie.HttpOnly = true;
                options.ExpireTimeSpan = TimeSpan.FromMinutes(5);

                options.LoginPath = "/AccountSystem/UserLogin";//options.ReturnUrlParameter = "returnUrl";
                options.LogoutPath = "/AccountSystem/UserLogout";
                options.AccessDeniedPath = "/AccountSystem/UserAccessDenied";
                options.SlidingExpiration = true;
            });
public IActionResult UserLogin(string returnUrl)
        {
            int languageId = HttpContext.Session.GetJSon<int>("LanguageId");var queryArray = returnUrl.Split("returnUrl=");
            if (queryArray.Length == 2)
            {
                returnUrl = queryArray[1].ToString();
            }
            if (queryArray.Length == 1)
            {
                returnUrl = queryArray[0].ToString();
            }

            var PageAccount = _unitOfWork.Pages.GetAll().Include(i => i.PageRoot).ThenInclude(i => i.Language)
                                        .Where(i => i.IsApproved && i.Language.IsApproved &&
                                                    i.PageRoot.ActionName == "UserLogin" &&
                                                    i.LanguageId == languageId).FirstOrDefault();

            return LocalRedirect("~/" + PageAccount.PageRoot.RootName + "/" + PageAccount.Url + "?returnUrl=" + returnUrl);
        }

when The authentication cookie timeout, I get this url : 

returnUrl="/Account/UserAccount?returnUrl=%2Fkullanici%2Fhesabim"

in this url, there is two question mark. I have to get returnUrl in form when that is posted. 

I figured out it. var queryArray = returnUrl.Split("returnUrl=");

But there is a problem. why is there two question mark ?

I tried to change returnUrl with loginReturnUrl

//options.ReturnUrlParameter = "loginReturnUrl";

then I get the same result again. 

how can I change my logic in this structure then I get just one question mark in returnUrl ?

thank you


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>