C
C#2mo ago
morry329#

created a new view but that view only outputs the html (of the login page!)

I am pretty sure I have been missing out something very trivial, so I appreciate another set of eyes again. Context: I made a new view (JumpToDashboard) on my simple ASP.NET core app in addition to the default Index and Privacy views. Whenever the browser runs the app and accesses to the JumpToDashboard page it only turns to the whole html of the login page (as per screenshot- I already found this embarassing). It was supposed to display a view with the title dashboard. I have tried moving around those tags [AllowAnonymous] [Authorize]. Still, JumpToDashboard always returns that embarrassing html https://pastebin.com/jCtNzRG6 This is my code, could anyone kindly point me in the right direction?
Pastebin
/Controller Class/using System.Diagnostics;using Microsoft.AspNet...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
No description
15 Replies
Angius
Angius2mo ago
Well, you are fetching whatever gets displayed at localhost:5001 and returning it as JSON So the code does exactly what you told it to In a blocking way, might I add, since you're using .Result instead of awaiting properly
morry329#
morry329#2mo ago
I see, thank you so much for helping me understand this code. I am very new to this. Could you give me some hint to await that properly (or do you have some links)?
Angius
Angius2mo ago
Instead of
public int Foo()
{
var x = SomethingAsync().Result;
}
public int Foo()
{
var x = SomethingAsync().Result;
}
you write
public async Task<int> Foo()
{
var x = await SomethingAsync();
}
public async Task<int> Foo()
{
var x = await SomethingAsync();
}
TizzyT
TizzyT2mo ago
yeah, id guess that changing the mime type would do the trick. Id also rename "string json" to something else like responseString or something.
Angius
Angius2mo ago
Question is, though: why are you fetching the HTML from localhost:5001 and returning it, instead of just... redirecting there? You're doing twice the work for zero benefit
TizzyT
TizzyT2mo ago
Maybe they are creating some kind of relay? proxy? idk lol wasnt the ask
Angius
Angius2mo ago
When someone asks "how do I eat soup with a fork" you say "use a spoon", even though that wasn't the ask either lol
TizzyT
TizzyT2mo ago
Ryan Laughs
YouTube
SOLVED! Can't Drink Soup with A Fork #lifehacks #funny
#lifehacks #funny #shorts Cheap and Cool Tech Accessories: https://amzn.to/3EawMWu Cheap and Cool Gaming Accessories: https://amzn.to/3nkfEXF Cheap and Cool Office Accessories: https://amzn.to/3vzvOAa 🗡️Buy Me A Knife🗡️ https://www.buymeacoffee.com/BigFishTech ❤️ SUPPORTING THE CHANNEL by shopping at Amazon via our affiliate link: https://amz...
morry329#
morry329#2mo ago
it's just everything was so new to me that I have no idea where I was fetching the HTML from Please bear with me asking this stupid question: what is the mime type you are referring to?
TizzyT
TizzyT2mo ago
text/html i believe line 66
morry329#
morry329#2mo ago
Ahh ok ContentType = "application/json", So my uneducated guess is: if I keep application/json like this the app will display the bunch of HTML on the browser, right? I assume changing this would do the trick
Angius
Angius2mo ago
If you want to keep this... uh, "innovative" idea instead of using a redirect, yes You will be returning HTML after all, not JSON
morry329#
morry329#2mo ago
well this innovative idea came from AI, ofc not from me. No idea what kind of company needs an app like this, returning HTML instead of JSON :kekw: I ended up adding this line return Redirect(requestUrl) I hope this is what you meant
Angius
Angius2mo ago
Yes, that's how you redirect
TizzyT
TizzyT2mo ago
considering we do non-sensical things all the time where I work, I wouldn't be surprised if they have something like it lol
Want results from more Discord servers?
Add your server