C
C#2mo ago
pycorn

Login Message Help

i am gonna ask to asp.net developers. is everyone think it is convenient to use asp.net mvc.
how can i resolve the following situations in more tidy way. situation: when i want to go the page which requires to login without login then i will be redirected to login page, but in this case , the message such as "Please login" should be shown. how can i solve this
33 Replies
Angius
Angius2mo ago
One of the scant few proper uses for a ViewBag IMO
Patrick
Patrick2mo ago
surely that's signified by the return url being populated as a query parameter
pycorn
pycorn2mo ago
so you mean, I have to decide whether showing the message by query parameter url. and I have to show it by javascript?
Angius
Angius2mo ago
Why Javascript? You can get query params perfectly fine in a controller or w/e
pycorn
pycorn2mo ago
of course, i mean that i have to show the message by javascript code
Patrick
Patrick2mo ago
there is no javascript involved
pycorn
pycorn2mo ago
the user already logined. but he then attempt the login page by typing url manually, what is the general good behavior in this case
Patrick
Patrick2mo ago
take them to wherever the login would usually redirect if there is no return
Angius
Angius2mo ago
Or just redirect to index
pycorn
pycorn2mo ago
Thank you very much But i think the mpa is somewhat uncomfortable. what about you?
Angius
Angius2mo ago
You're making an SPA, then? So handle it all with JS Return an error message from the API and there, done
pycorn
pycorn2mo ago
Thank you very much. I have been developing the frontend with react.when i am using the spa, all is comfortable. when i use the mpa. i have faced the following challenge. situation: the blog list is displayed. the user deleted one of it. the the blog list must be updated. but in this case , the success message should be displayed. should i resolve this situation by api and axios or ajax. or how can i resolve it with traditional mpa form submit method
Angius
Angius2mo ago
Well, yeah, just submit the form What's challenging here, exactly?
pycorn
pycorn2mo ago
i metioned that i wanted to show the success message such as "blog successfully deleted". but how can i show this message in mpa
Angius
Angius2mo ago
After successful deletion redirect wherever and pass the success message Or a message ID Or some such Then pass it to the view with viewbag or w/e
pycorn
pycorn2mo ago
then i should show that message in javascirpt
Angius
Angius2mo ago
Why?
pycorn
pycorn2mo ago
@section Scripts { <script> $(document).ready(function () { var successMessage = '@ViewBag.SuccessMessage'; if (successMessage) { toastr.success(successMessage); } }); </script> } this is my code . am i wrong
Angius
Angius2mo ago
Well, if you want to use JS to show a toast or a popup or whatever, sure If you want to use JS to do something you need JS Yes
pycorn
pycorn2mo ago
are there some other ways to show the messages
Angius
Angius2mo ago
Just... render it?
public async Task<IActionResult> IndexOrWhatever([FromQuery]int? status)
{
ViewBag["message"] = Messages[status];
// ...
return View(ungabunga);
}
public async Task<IActionResult> IndexOrWhatever([FromQuery]int? status)
{
ViewBag["message"] = Messages[status];
// ...
return View(ungabunga);
}
<h1>@Model.Skunga</h1>
@if(ViewBag["message"] is string m)
{
<div class="message">@m</div>
}
<h1>@Model.Skunga</h1>
@if(ViewBag["message"] is string m)
{
<div class="message">@m</div>
}
pycorn
pycorn2mo ago
oh, i got it. thank you very much\ could you give me some sample codes for me to catch the pattern
Angius
Angius2mo ago
It's not any sort of a pattern? You just pass the data around Messages is some Dictionary<int, string> here for example That has [69] = "ayy yoo boss thingamajig has been yeeted yo" If status is 69 that's the message you get You stuff it into the viewbag Get it from the viewbag Show it
pycorn
pycorn2mo ago
oh, thank you very much. so i can store Dictionary globally
Angius
Angius2mo ago
Ideally, you'd have some service or w/e injected as a singleton But yeah, basically
pycorn
pycorn2mo ago
oh, i learned about di and service.
Angius
Angius2mo ago
There you go, then
pycorn
pycorn2mo ago
i have some more. i put the back button on the page. how can i handle the back navigation , do you think
Angius
Angius2mo ago
uh Just a link? Or just let the user use their browser They tend to have "back" buttons
pycorn
pycorn2mo ago
Yes mabe link or button .I think i have some problems with using browser's history I manually put back button on my blog edit and detail page
Angius
Angius2mo ago
Nothing is simpler than browser history? Pressing "back" takes you back 's it
pycorn
pycorn2mo ago
I will do it. z*? what architecture do you like to use, when developing web applications using asp.net. could you tell me about your experience when i read the article about cqrs, the author recommended to use different orm to save and get. what do you think about this
Angius
Angius2mo ago
For the API in particular I do use CQRS Kinda-sorta, since it's Immediate.Handlers For the SSR part, I just go with Razor Pages Everything just backed by EF Core, I see zero reason to use multiple ORMs
Want results from more Discord servers?
Add your server