Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7867653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:45:42+00:00 2026-06-03T00:45:42+00:00

I have a really weird scenario that I’m stuck on. I have a ASP.Net

  • 0

I have a really weird scenario that I’m stuck on. I have a ASP.Net MVC 4 app where I’m authenticating a user and creating an authCookie and adding it to the response’s cookies then redirecting them to the target page:

            if (ModelState.IsValid)
            {
                var userAuthenticated = UserInfo.AuthenticateUser(model.UserName, model.Password);

                if (userAuthenticated)
                {
                    var userInfo = UserInfo.FindByUserName(model.UserName);

                    //SERIALIZE AUTHENTICATED USER
                    var serializer = new JavaScriptSerializer();
                    var serializedUser = serializer.Serialize(userInfo);
                    var ticket = new FormsAuthenticationTicket(1, model.UserName, DateTime.Now, DateTime.Now.AddMinutes(30), false, serializedUser);
                    var hash = FormsAuthentication.Encrypt(ticket);
                    var authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, hash) {Expires = ticket.Expiration};

                    Response.Cookies.Add(authCookie);

                    if (Url.IsLocalUrl(model.ReturnUrl) && model.ReturnUrl.Length > 1 && model.ReturnUrl.StartsWith("/") && !model.ReturnUrl.StartsWith("//") && !model.ReturnUrl.StartsWith("/\\"))
                    {
                        return Redirect(model.ReturnUrl);
                    }

                    var url = Url.Action("Index", "Course");
                    return Redirect(url);
                }

                ModelState.AddModelError("", "The user name or password provided is incorrect.");
            }

This is working just fine in all browsers. I can login and access the secure pages in my app.

My client is requesting an android version of this app. So, I’m trying to figure out how to convert this app into an APK file. My first attempt is to create a simple index.html page with an iframe that targets the application. This works just fine in Firefox and IE 9. However, when accessing the index.html page that contains the iframe that points to the app via Chrome, I get past the login code above and the user gets redirected to the secure controller, but the secure controller has a custom attribute to make sure the user is authenticated:

public class RequiresAuthenticationAttribute : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (filterContext.HttpContext.User.Identity.IsAuthenticated) return;
            if (filterContext.HttpContext.Request.Url == null) return;

            var returnUrl = filterContext.HttpContext.Request.Url.AbsolutePath;

            if (!filterContext.HttpContext.Request.Browser.IsMobileDevice)
            {
                filterContext.HttpContext.Response.Redirect(FormsAuthentication.LoginUrl + string.Format("?ReturnUrl={0}", returnUrl), true);
            }
            else
            {
                filterContext.HttpContext.Response.Redirect("/Home/Home", true);
            }           
        }
    }

My app is failing on: filterContext.HttpContext.User.Identity.IsAuthenticated. IsAuthenticated is always false, even though the user was authenticated in the code above.

Keep in mind this only happens when accessing the app via iframe in Chrome. If I access the app directly instead of via iframe, then everything works just fine.

Any ideas?

UPDATE:

My controller extends SecureController. In the constructor of SecureController I have the code that deserializes the user:

public SecureController()
        {
            var context = new HttpContextWrapper(System.Web.HttpContext.Current);

            if (context.Request.Cookies[FormsAuthentication.FormsCookieName] != null)
            {
                var serializer = new JavaScriptSerializer();
                var cookie = context.Request.Cookies[FormsAuthentication.FormsCookieName].Value;
                var ticket = FormsAuthentication.Decrypt(cookie);
                CurrentUser = serializer.Deserialize<UserInfo>(ticket.UserData);
            }
            else
            {
                CurrentUser = new UserInfo();
            }


            //if ajax request and session has expired, then force re-login
            if (context.Request.IsAjaxRequest() && context.Request.IsAuthenticated == false)
            {
                context.Response.Clear();
                context.Response.StatusCode = 401;
                context.Response.Flush();
            }
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T00:45:44+00:00Added an answer on June 3, 2026 at 12:45 am

    First, you should be deriving from AuthorizeAttribute, not an ActionFilterAttribute. Authorization attributes execute before the method is even called at a higher level of the pipeline, while ActionFilters execute much further down, and other attributes can execute before yours.

    Secondly, you aren’t showing the code you use to decrypt the ticket and set the IPrincipal and IIdentity. Since that’s where the problem is, it’s odd that you didn’t include it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been having a really weird problem. I have a mutable array that is
I have a really weird problem that is driving me crazy. I have a
I have a really weird situation. The idea is there is a scroller that
This is a really weird problem: I have set up the authlogic_openid_selector_example app .
Have a really weird one here. The app has two targets, just to be
I have a really weird problem with /bin/bash and a script that uses printf
I have this really weird problem in my code (.Net Framework 3.5). So, in
I have a really weird thing happening. In my app delegate, I'm calling presentModalViewController:
This is the second time that I have this really weird problem with WCF
I have a really weird issue that I can't figure out with comparing objects

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.