5

I'm working on a .net Core MVVC project devloped in VS Community 2017 and using IIS Express 10 and I'm having issues with TempData not working on two of the 3 computers I develop on. At one point it did work on all three.

I use TempData to store info during redirects and then transfer TempData to ViewData to display on the View page. I had issues with something (I don't remember what it was now) and was getting help from a co-worker and during his troubleshooting a box popped up and said something about SSL and I don't remember what he clicked but since then TempData stopped working. The one thing I think he did do differently than me was along the top in the Debug area, he clicked the IIS Express dropdown and chose the project name option instead. TempData now shows up as null after the redirect. When I open up the project on my home computer, TempData works with no issues. I have a 3rd computer I do some development on and it used to work on that until the SSL box popped up on that as well and it stopped working. I'm guessing that it's redirecting to the page I want but it's making a pit-stop somewhere along the way and the data is lost.

I tried uninstalling and reinstalling both VS and IIS Express with no change. I also tried deleting the .vs folder in the solution with no change. I tried clearing out the websites using the IIS Express command in the command prompt. I also tried it in both Chrome (where it used to work) and Internet Explorer with no change. I've tried running it with debugging and without debugging with no change.

So, TempData no longer works on two computers (both Windows 10 if it matters) and my home computer (Windows 7) works just fine. Anyone have any ideas?

Alex Kulinkovich
  • 4,408
  • 15
  • 46
  • 50
HazardousGlitch
  • 150
  • 1
  • 14
  • Try using a proxy such as fiddler to see what requests are being made from the browser. It may help diagnose the issue – ste-fu Nov 02 '18 at 12:52
  • What did the box about ssl say? – Aamir Masood Nov 02 '18 at 14:51
  • Can you explain about redirect in "TempData now shows up as null after the redirect"? As per my understanding, tempdata works only with consecutive requests from same page on same client to the same server. It will be lost, if you are redirecting or not accessing the tempdata dictionary during consecutive requests. – Hitesh Gaur Nov 02 '18 at 15:50
  • @ste-fu I used the developer tools in Chrome to watch the process and it works as I expected. From one page to the next with nothing inbetween, if that's what you're referring to. – HazardousGlitch Nov 02 '18 at 18:52
  • @AamirMasood I don't know. I didn't read it before my co-worker clicked OK and I missed it when it happened to me. – HazardousGlitch Nov 02 '18 at 18:53
  • @HiteshGaur TempData is used to move data from one controller and send it to the next controller to be processed and displayed on page as ViewData. When it gets to the next controller, it is empty. – HazardousGlitch Nov 02 '18 at 18:58
  • @HazardousGlitch: That's where it may be going wrong. I am suggesting it is just a possibility. It is not the controller, it is for only subsequent HTTP request. 'Although ASP.NET MVC TempData stores it’s content in Session state but it gets destroyed earlier than a session object. TempData gets destroyed immediately after it’s used in subsequent HTTP request' is described at https://www.codeproject.com/Articles/786603/Using-TempData-in-ASP-NET-MVC – Hitesh Gaur Nov 02 '18 at 19:11
  • @HiteshGaur According to Microsoft, "Represents a set of data that persists only from one request to the next." So it should have no issue going from one controller to the other and it doesn't have issues on one of my computers. I have the same exact code on all three computers but two don't work right. I'm leaning towards a setting somewhere that needs to be changed but I haven't found it yet. – HazardousGlitch Nov 02 '18 at 19:38
  • 1
    @HazardousGlitch: that makes sense, only if, on your one working machine, it is not getting redirected or not using ssl in the same way that it is using on other 2 non working computer. That is all. – Hitesh Gaur Nov 02 '18 at 19:53
  • can you try and simulate the issue in a test application? The possible issues are ssl and tempdata key being used more than once – Aamir Masood Nov 03 '18 at 02:20
  • @AamirMasood I created a test project on both the working computer and a non-working computer. It works fine on the working computer and does not work on the non-working computer. – HazardousGlitch Nov 06 '18 at 19:45

2 Answers2

2

by close look to your question, at first

"a co-worker and during his troubleshooting a box popped up and said something about SSL and I don't remember what he clicked"

mybe your co-worker enabled ssl on development environment and after run the project you have to trust local IIS certificate.

I think you have to config cookie for using SSL for example <httpCookies requireSSL="true" /> or you can disable SSL for development and every thing gonna be OK.

for sure you can check that in home computer your URL have HTTP and in other two computers the URL starts with HTTPS.

On the other hands I suggest you to compare the web.config structures.

Mehdi
  • 1,731
  • 1
  • 18
  • 33
  • I double checked and SSL is enabled on all three computers with valid certificates. I don't have a web.config file to edit.In Project -> [projectname] -> Debug, Enable SSL is checked as well. – HazardousGlitch Oct 29 '18 at 14:01
0

I found the answer finally at https://github.com/aspnet/Mvc/issues/8233

To fix the issue, I modified my Startup.cs file so that app.UseCookiePolicy(); was placed after app.UseMvc();. I don't know why it only affects one of my computers but it fixes the issue.

HazardousGlitch
  • 150
  • 1
  • 14