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
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
One of the scant few proper uses for a
ViewBag
IMOsurely that's signified by the return url being populated as a query parameter
so you mean, I have to decide whether showing the message by query parameter url. and I have to show it by javascript?
Why Javascript?
You can get query params perfectly fine in a controller or w/e
of course, i mean that i have to show the message by javascript code
there is no javascript involved
the user already logined. but he then attempt the login page by typing url manually, what is the general good behavior in this case
take them to wherever the login would usually redirect if there is no return
Or just redirect to index
Thank you very much
But i think the mpa is somewhat uncomfortable. what about you?
You're making an SPA, then?
So handle it all with JS
Return an error message from the API and there, done
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
Well, yeah, just submit the form
What's challenging here, exactly?
i metioned that i wanted to show the success message such as "blog successfully deleted". but how can i show this message in mpa
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
then i should show that message in javascirpt
Why?
@section Scripts {
<script>
$(document).ready(function () {
var successMessage = '@ViewBag.SuccessMessage';
if (successMessage) {
toastr.success(successMessage);
}
});
</script>
}
this is my code . am i wrong
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
are there some other ways to show the messages
Just... render it?
oh, i got it. thank you very much\
could you give me some sample codes for me to catch the pattern
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 itoh, thank you very much. so i can store Dictionary globally
Ideally, you'd have some service or w/e injected as a singleton
But yeah, basically
oh, i learned about di and service.
There you go, then
i have some more. i put the back button on the page. how can i handle the back navigation , do you think
uh
Just a link?
Or just let the user use their browser
They tend to have "back" buttons
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
Nothing is simpler than browser history?
Pressing "back" takes you back
's it
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
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