0

I am totally new to ASP.NET MVC 5 and I need some help.
Background:
I am building my own web site because I would like to productise it eventually.
It's a form of eating your own dog food.
I have created a default application (you know, the one with all the MS links) and am modifying it for my own needs.
The first thing I did is what you should NEVER do :) i.e. modify the database tables manually to add roles and give my spanking new user the admin role. I did google but either I asked it the wrong question or missed the link totally. Either way, I modified them manually and it seemed to "work" (i.e. no db integrity errors were raised in Visual Studio).

I then added a "Products" table and did the scaffolding from the model to the controller, views, etc (thanks Mr Google). I also found how to stop showing links in the Index view for the data manipulation if you're not an admin.

Now, as I implied, I had registered a user, so I was curious to see what would happen when I returned and tried to call (from URL) my brand new toy. That's when a very useful "Object reference not set..." came up.

I have therefore a few questions:

  1. Did I do anything stupid (likely)?
  2. If I did, what is it?

The stack trace does not mention anything to do with login or errors in the db, except for the following lines:

Microsoft.Owin.Security.Cookies.CookieAuthenticationProvider.Exception(CookieExceptionContext context) +49
   Microsoft.Owin.Security.Cookies.<AuthenticateCoreAsync>d__2.MoveNext() +3698

which are just below the main line detailing the error.

So, if I am correct, it tried to access a cookie it didn't find.

What do you think is the most likely cause of this issue?

Suggestions?

[UPDATE]
Ok, so I have tried digging a bit to see whether I could find something interesting... and eventually I did.
Buried in one of the many files, I found this comment:

Note the authenticationType must match the one defined in 
CookieAuthenticationOptions.AuthenticationType

Which seems to match with the stack trace outlined above.
I did check and it seems to me that they are the same(thanks to Google I found where to look).

I am stuck.

Please help!

Andrea Raimondi
  • 527
  • 8
  • 30
  • It is worth noting that, after every run, I close the browser window and stop debugging. This should not be a problem and the cookie should be there, but I know jack of ASP.NET so I am not sure what is right or wrong here. – Andrea Raimondi Sep 17 '15 at 16:06
  • better provide code you used in authentication – J Santosh Sep 17 '15 at 16:58
  • This post might be helpful: http://stackoverflow.com/questions/26327092/why-is-owin-throwing-a-null-exception-on-new-project – David Tansey Sep 17 '15 at 16:58
  • Hi @JSantosh ! I did not use any custom code. The authentication is all managed by the wizard, I didn't touch anything :) the only thing I have touched is the relationship table between users and roles to assign a role to a user and the roles table to define the roles. That's it. – Andrea Raimondi Sep 17 '15 at 18:24
  • Hey @DavidTansey ! You were absolutely right :D That was the way to go. Oh, please post the above as answer, so that I can accept it :) – Andrea Raimondi Sep 17 '15 at 19:06
  • @AndreaRaimondi there is no accepted answer on the post that I linked. Which suggested approach from that post ended up working for you? – David Tansey Sep 18 '15 at 14:51
  • Does this answer your question? [Why is \[Owin\] throwing a null exception on new project?](https://stackoverflow.com/questions/26327092/why-is-owin-throwing-a-null-exception-on-new-project) – Michael Freidgeim Sep 24 '21 at 08:44

0 Answers0