4

I am using simple method for creating cookies.

FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
return RedirectToAction("Index", "Dashboard");

Somehow I debugged my application and found that User.Identity.IsAuthenticated is always false and User.Identity.Name is also null.

Note: Above behavior is only for SAFARI and works absolutely fine with other browsers like I.E, Firefox and chrome.

I know my questions is duplicated and Google gave me enough links for solution but I can't seem to fix my issue. I am using .NET 4.5 and Safari version is 5+.

trailmax
  • 34,305
  • 22
  • 140
  • 234
Waqar Ahmed
  • 1,414
  • 2
  • 15
  • 35
  • Maybe you should try listing some things you have already tried? [This answer](http://stackoverflow.com/a/11558857/2422173) for example says that Safari has trouble with the encoding of cookie values, have you tried that? – Thomas Mulder Dec 01 '15 at 11:32
  • Do you have any sample which is stripped down version of your original code to repro this issue? – Joy George Kunjikkuru Dec 08 '15 at 02:17

1 Answers1

1

Are you sure following line is working fine i.e. Authentication cookie is being set correctly ? You can always check cookies created for a site. If you don't know just google it. Its fairly simple trick.

Following line actually sets an authentication cookie FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);

If the cookie is not being set that means cookies are disabled on Safari. If they are being set then we can dig further.

In case the cookie is being set then compare the cookie with the one created in another browswer. And may be post it here so we can see whats going on.

ItsZeus
  • 142
  • 12
  • Cookies are not being set using `FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe)`, also cookies are enabled in Safari. Kindly read the question carefuly – Waqar Ahmed Dec 01 '15 at 12:20
  • Waqar bhai, regarding your question, It is not mentioned the cookies are not set. Having said that its clear the issue is cookie not being set. I'll check it on my end and see if I can duplicate the issue. – ItsZeus Dec 01 '15 at 12:49
  • Umm i think the correct authentication is set that's why it is working in other browsers. – Waqar Ahmed Dec 01 '15 at 12:56
  • see if this post helps you http://stackoverflow.com/questions/14825805/cookies-not-setting-in-safari-6 – ItsZeus Dec 01 '15 at 13:02
  • i just duplicated it waqar bhai using Safari 5.1.7 First time User.Identity.IsAuthenticated was false but i closed my safari reopened it and it was set to true. Similar wsa the case with User.Identity.Name. Should you need I can share my project with you – ItsZeus Dec 02 '15 at 08:44
  • Following code is what I used on button click. **protected void Login_Click(object sender, EventArgs e) { FormsAuthentication.SetAuthCookie(UserName.Text, true); Output.Text = User.Identity.IsAuthenticated.ToString(); Output2.Text = User.Identity.Name; }** Authentication in Web.Config is defined as – ItsZeus Dec 02 '15 at 08:47
  • Did u try it yet ? I have tried it multiple times and so far everytime it works like a charm! – ItsZeus Dec 03 '15 at 05:39