C
C#3mo 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
Angius3mo ago
One of the scant few proper uses for a ViewBag IMO
Patrick
Patrick3mo ago
surely that's signified by the return url being populated as a query parameter
pycorn
pycornOP3mo 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
Angius3mo ago
Why Javascript? You can get query params perfectly fine in a controller or w/e
pycorn
pycornOP3mo ago
of course, i mean that i have to show the message by javascript code
Patrick
Patrick3mo ago
there is no javascript involved
pycorn
pycornOP3mo 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
Patrick3mo ago
take them to wherever the login would usually redirect if there is no return
Angius
Angius3mo ago
Or just redirect to index
pycorn
pycornOP3mo ago
Thank you very much But i think the mpa is somewhat uncomfortable. what about you?
Angius
Angius3mo ago
You're making an SPA, then? So handle it all with JS Return an error message from the API and there, done
pycorn
pycornOP3mo 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
Angius3mo ago
Well, yeah, just submit the form What's challenging here, exactly?
pycorn
pycornOP3mo 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
Angius3mo 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
pycornOP3mo ago
then i should show that message in javascirpt
Angius
Angius3mo ago
Why?
pycorn
pycornOP3mo 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
Angius3mo 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
pycornOP3mo ago
are there some other ways to show the messages
Angius
Angius3mo 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
pycornOP3mo ago
oh, i got it. thank you very much\ could you give me some sample codes for me to catch the pattern
Angius
Angius3mo 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
pycornOP3mo ago
oh, thank you very much. so i can store Dictionary globally
Angius
Angius3mo ago
Ideally, you'd have some service or w/e injected as a singleton But yeah, basically
pycorn
pycornOP3mo ago
oh, i learned about di and service.
Angius
Angius3mo ago
There you go, then
pycorn
pycornOP3mo ago
i have some more. i put the back button on the page. how can i handle the back navigation , do you think
Angius
Angius3mo ago
uh Just a link? Or just let the user use their browser They tend to have "back" buttons
pycorn
pycornOP3mo 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
Angius3mo ago
Nothing is simpler than browser history? Pressing "back" takes you back 's it
pycorn
pycornOP3mo 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
Angius3mo 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