In my MVC5 application, users log in from external software without a separate login. After some times the external application can be closed and in this case a login form should appear.
I receive an event
Software.DataChange + = delegate ()
{
.... code goes here
IsUserLoggedIn = false;
};
And now the globally defined variable IsUserLoggedIn changes.
Now the login view should be called. And that's where my problems begin.
Can I do this in the controller?
Or can I assign a field via SignalR and then trigger a reload of the page? SignalR is already used for some progress bars.
Thanks
Ottilie
Related
I am using .net project and create one web page to use with SignalR. This code below working with one web page. Client side:
$.connection.hub.start().done(function () { });
var chat = $.connection.chatHub;
chat.client.broadcastMessage = function (name, message) { };
Server side:
var context =
Microsoft.AspNet.SignalR.GlobalHost.ConnectionManager.GetHubContext<SignalRChat.ChatHub>();
context.Clients.All.broadcastMessage(name, message);
Then I create second web page and copy client and server code from page 1.
Problem is that when I call
context.Clients.All.broadcastMessage(name, message);
from second page. it fired function
chat.client.broadcastMessage
on first page. How can I fixed that to fired client side for page 2?
Thanks
Do you want it to fire on both pages -
I suspect you did not create a connection on the page 2. Once you have a valid connection on page 2 it would fire on both page 1 and 2 if you had both open. Or only on the page you have open.
If you want it to fire on each page but not both pages you have some changes to make. You have several options you can go with here with no additional context:
Really simple - rename chat.client.broadcastMessage on page 2 to something else and call it from the server with a new method.
Look into Groups - updating context.Clients.Group(groupname).broadcastMessage(name, message) you can send messages to users on page1 (assuming you have a group for page 1 and page 2) and then only send messages to users on page 2 when needed.
This is iOS specific issue.
I have completed all the steps suggested in document over here https://azure.microsoft.com/en-in/resources/samples/active-directory-b2c-xamarin-native/
In Andtoid it is working fine. But in iOS it is not returning back to application after successful login.
Yes, Login page is displaying properly we can enter the credentials over there but once login in successful then browser is closed but debugger not attaching back to application.
I have Eneabled Keychain access, Added Url Types in info.plist and also added below code to AppDelegate.cs
public override bool OpenUrl(UIApplication app, NSUrl url, NSDictionary options)
{
AuthenticationContinuationHelper.SetAuthenticationContinuationEventArgs(url);
return true;
}
And on FInishLaunching event I have added below code
var authenticationService = DependencyService.Get();
// Default system browser
authenticationService.SetParent(null);
Actually I am calling SignInAsync method from OnAppearing event of view. So after successful validation OnAppearing event is firing again and it lost the previous flow.
Please let me know if I am missing something. Your help is much appreciated.
Thanks.
I implemented my own login system, because I'm using a third party web service to authenticate users against an enterprise authentication system. As such, I built a form that calls a server method to make the web service call to the auth system, and if the credentials are valid, it sets a session variable with the user's id. This is how I change the template to show the main screen of the application and not the login screen. Works fine. And the logout button then just sets that userid session variable to false, effectively hiding the main application screen and showing the login form again.
<body>
{{#if loggedInUser}}
{{> navbar}}
{{> mainScreen}}
{{else}}
{{> customLogin}}
{{/if}}
</body>
Template.navbar.helpers({
loggedInUser: function () {
return Session.get('userName');
}
});
'click #logoutButton': function () {
Session.set("userName", false);
}
What I have discovered though, is that the local minimongo collections/subscriptions are still in the browser, and accessible in the console, after the user logs out.
I did some searching but didn't find concrete solutions as to how to properly clear out (or stop?) these subscriptions on the client. In fact, the top 3 hits on a search for "meteor publish subscribe " don't mention stopping or security upon logout.
One suggestion on SO was to save the subscription handle ... but I'm calling subscribe multiple times, so it seems I would have to store up an array depending on how many different subscribes the user triggered during their use of the application, and then go through them calling "stop" on each handle when logging out??
I'm hoping there's a simple way to stop all subscriptions... seems like a logical thing to do for security when a user clicks a logout button.
Thanks!
Could you not use .stop() function on the collection?
var subscription = Meteor.subscribe("info");
//on logout
subscription.stop();
According to the docs:
stop()
Cancel the subscription. This will typically result in the server directing the client to remove the subscription's data from the client's cache.
Updated: Maybe check out this package: Subs Manager. It appears they may be able to do what you want, specifically from their readme:
Clear Subscriptions
In somecases, we need to clear the all the subscriptions we cache. So, this is how we can do it.
var subs = new SubsManager();
// later in some other place
subs.clear();
I'm trying to find examples on how to get real time updates using a web service in ASP.NET MVC (Version doesn't matter) and posting it back to a specific user's browser window.
A perfect example would be a type of chat system like that of facebooks' where responses are send to the appropriate browser(client) whenever a message has been posted instead of creating a javascript timer on the page that checks for new messages every 5 seconds. I've heard tons of times about types of sync programs out there, but i'm looking for this in code, not using a third party software.
What i'm looking to do specifically:
I'm trying to create a web browser chat client that is SQL and Web Service based in ASP.NET MVC. When you have 2-4 different usernames logged into the system they chat and send messages to each other that is saved in an SQL database, then when there has been a new entry (or someone sent a new message) the Web Service see's this change and then shows the receiving user the new updated message. E.G Full Chat Synced Chat using a Web Service.
The thing that really stomps me in general is I have no idea how to detect if something new is added to an SQL table, and also I have no idea how to send information from SQL to a specific user's web browser. So if there are people userA, userB, userC all on the website, i don't know how to only show a message to userC if they are all under the username "guest". I would love to know hot to do this feature not only for what i'm trying to create now, but for future projects as well.
Can anyone point me into the right direction please? I know SQL pretty well, and web services i'm intermediate with.
You can use SignalR for this task.
Via Scott Hanselman:
Create Asp.net mvc empty application
install nuget package of SignalR
Add new Controller (as example HomeController):
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
}
Create view Index with javascript references:
#Url.Content("~/Scripts/jquery-1.6.4.min.js")"
"#Url.Content("~/Scripts/jquery.signalR.js")"
and function:
$(function () {
var hub = $.connection.chatHub;
hub.AddMessage = function (msg) {
$('#messages').append('<li>' + msg + '</li>');
};
$.connection.hub.start().done(function() {
$('#send').click(function() {
hub.send($('#msg').val());
});
});
});
Create class ChatHub:
public class ChatHub:Hub
{
public void Send(string message)
{
Clients.AddMessage(message);
}
}
Im trying to use the sdk without a canvas application, so have followed steps 1-7 in the quickstart guide up to adding the facebookSettings property in the Web.config.
I have added an image to my page and an onclick event that contains the below code. but when I click the button, it just takes me to the home page (CancelUrlPath).
Changing the Authorizer to a CanvasAuthorizer results in FB loading the login screen, but I get an error 404 not found on the call (even after inserting the handlers into the config)..
fbApp = new FacebookApp();
authorizer = new Authorizer(fbApp) {Perms = requiredAppPermissions};
authorizer.ReturnUrlPath = "http://localhost/User/UserRegister.aspx";
authorizer.CancelUrlPath = "http://localhost/";
if (authorizer.Authorize(this.Context))
{
Response.Write("hello");//never gets here
}
Can anyone help please?
Note: I've set the canvas and site url to http://localhost/ on the FB app settings.
If you are just building a simple connect website you really don't want to use the server side authentication tools to authenticate your user. Just use the Javascript SDK to athenticate the user. If you need to do anything on the server side, the FacebookApp class will automatically pick up the user's session from the values stored in the cookies.
See the Facebook documentation for more details: http://developers.facebook.com/docs/guides/web/#registration