SignalR MCQs ASP.NET 

What is SignalR primarily used for in ASP.NET applications?
A. Real-time web functionality such as chat and live notifications
B. File upload and download management
C. Server-side form processing
D. Static page rendering
Answer: A

Which component is essential for establishing a SignalR connection in an ASP.NET Core application?
A. Hub
B. WebSocket
C. HttpClient
D. SignalRClient
Answer: A

What is the primary function of a SignalR Hub?
A. To handle communication between clients and the server
B. To store session data
C. To manage database connections
D. To handle HTTP requests
Answer: A

Which method is used to send a message from the server to all connected clients in a SignalR Hub?
A. Clients.All.SendAsync()
B. SendToAllClients()
C. BroadcastMessage()
D. PushToClients()
Answer: A

How do you create a new Hub in an ASP.NET Core application?
A. By inheriting from the Hub class and defining methods for communication
B. By using the HubContext class directly
C. By configuring SignalR in the Startup class only
D. By using a SignalRHub class provided by the framework
Answer: A

Which SignalR feature enables automatic reconnection of clients?
A. AutomaticReconnect
B. ReconnectPolicy
C. RetryPolicy
D. AutoReconnect
Answer: A

What is a HubConnection in SignalR?
A. A connection object that manages communication between the client and server
B. A server-side component for managing multiple Hubs
C. A method for handling HTTP requests
D. A configuration setting for SignalR
Answer: A

In SignalR, what is the purpose of the SendAsync method on the client?
A. To send messages or invoke methods on the server-side Hub
B. To establish a new connection to the Hub
C. To handle incoming messages from the server
D. To close the connection to the Hub
Answer: A

Which class is used to configure SignalR services in an ASP.NET Core application?
A. Startup
B. HubConfiguration
C. SignalRConfig
D. SignalRService
Answer: A

How do you ensure that SignalR works with WebSockets in ASP.NET Core?
A. By configuring WebSocket support in the Startup class
B. By directly using WebSocket APIs
C. By using a third-party library
D. By setting UseSignalR in the ConfigureServices method
Answer: A

What is the purpose of IHubContext<T> in SignalR?
A. To send messages to clients from outside a Hub class
B. To manage client connections
C. To configure the Hub service
D. To handle server-side methods
Answer: A

What does the OnConnectedAsync method in a SignalR Hub do?
A. It is called when a client successfully connects to the Hub
B. It is invoked when a message is received from the client
C. It is triggered when the Hub is initialized
D. It is called when the client disconnects from the Hub
Answer: A

How can you broadcast a message to a specific group of clients in SignalR?
A. By using Clients.Group("groupName").SendAsync()
B. By using SendToGroup("groupName")
C. By calling BroadcastToGroup("groupName")
D. By using Groups.Broadcast("groupName")
Answer: A

What is a ClientProxy in SignalR?
A. An object used to invoke methods on the client from the server
B. A proxy server for managing HTTP requests
C. A class for configuring the SignalR service
D. An object that handles database operations
Answer: A

Which method in SignalR is used to join a group?
A. Groups.AddToGroupAsync()
B. JoinGroup()
C. AddToGroup()
D. EnterGroup()
Answer: A

How do you handle incoming messages from the server on the client side using SignalR?
A. By defining methods on the client that match the method names used on the server
B. By using ReceiveAsync method directly
C. By configuring an event listener for incoming messages
D. By overriding the OnMessageReceived method
Answer: A

What is the function of OnDisconnectedAsync in a SignalR Hub?
A. To handle logic when a client disconnects from the Hub
B. To manage reconnection attempts
C. To process messages from the client
D. To configure the Hub’s authentication
Answer: A

Which method is used to remove a client from a group in SignalR?
A. Groups.RemoveFromGroupAsync()
B. RemoveClientFromGroup()
C. DropFromGroup()
D. ExitGroup()
Answer: A

How can you secure SignalR connections in ASP.NET Core?
A. By using authentication and authorization middleware
B. By configuring SSL/TLS only
C. By using custom connection strings
D. By encrypting messages manually
Answer: A

What type of connection does SignalR fall back to if WebSockets are not supported?
A. Long polling or Server-Sent Events (SSE)
B. Traditional HTTP requests
C. FTP connections
D. UDP connections
Answer: A

How do you configure SignalR in the Startup class of an ASP.NET Core application?
A. By adding SignalR services in ConfigureServices and mapping hubs in Configure
B. By using AddSignalR() in the Configure method
C. By configuring SignalR in the Program class
D. By using SignalRConfig class directly
Answer: A

Which method on the HubConnection object is used to start the connection to the SignalR Hub?
A. StartAsync()
B. Connect()
C. BeginConnection()
D. Establish()
Answer: A

What is the purpose of the HubCallerContext in SignalR?
A. To provide information about the caller, such as connection ID and user identity
B. To manage connection lifetime
C. To handle message serialization
D. To configure client-side settings
Answer: A

Which protocol does SignalR use by default for real-time communication?
A. WebSockets
B. HTTP
C. FTP
D. SMTP
Answer: A

What does the OnReconnected method do in SignalR?
A. It is called when a previously disconnected client successfully reconnects
B. It handles incoming messages from clients
C. It manages connection timeouts
D. It configures the initial connection setup
Answer: A

What is the role of HubFilter in SignalR?
A. To apply cross-cutting concerns such as logging and authorization to Hub methods
B. To filter incoming messages based on content
C. To configure the connection settings
D. To manage reconnection strategies
Answer: A

How can you use SignalR to implement a real-time notification system?
A. By creating a Hub that clients connect to and send notifications through methods
B. By polling the server periodically
C. By using HTTP long polling
D. By configuring a database trigger
Answer: A

What is a Stream in SignalR?
A. A continuous flow of data between the server and client
B. A static file served by the server
C. A single HTTP request
D. A database query
Answer: A

Which method is used to send a message to a specific client in SignalR?
A. Clients.Client("connectionId").SendAsync()
B. SendToClient("connectionId")
C. SendMessageToClient("connectionId")
D. ClientSend("connectionId")
Answer: A

How does SignalR handle connection management in a clustered environment?
A. By using a backplane to synchronize messages across multiple servers
B. By establishing direct connections between clients and each server
C. By using a single server to handle all connections
D. By relying on client-side connection management
Answer: A

What is the purpose of the HubConnectionBuilder in SignalR?
A. To configure and build a HubConnection instance with specific options and settings
B. To create a new Hub class
C. To manage server-side Hub methods
D. To handle client-side scripts
Answer: A

How can you implement custom authentication in a SignalR application?
A. By using ASP.NET Core authentication middleware and configuring it in the Startup class
B. By implementing custom authentication within the Hub itself
C. By handling authentication manually in client-side code
D. By using SignalR’s built-in authentication options
Answer: A

What is the HubInvocationContext used for in SignalR?
A. To provide context information for method invocations on the Hub
B. To manage connection state
C. To handle message serialization
D. To configure client-side settings
Answer: A

Which feature of SignalR allows for sending streaming data to clients?
A. Stream method
B. Broadcast method
C. Send method
D. Push method
Answer: A

How can you use SignalR with ASP.NET Core Identity for user management?
A. By integrating ASP.NET Core Identity with SignalR’s authentication and authorization mechanisms
B. By configuring separate user management systems
C. By using custom authentication schemes only
D. By implementing user management directly in the Hub
Answer: A

What is the purpose of HubConnectionState in SignalR?
A. To indicate the current state of the connection, such as connected, disconnected, or reconnecting
B. To manage Hub methods
C. To handle client-side data processing
D. To configure server-side settings
Answer: A

How does SignalR support multi-language applications?
A. By enabling real-time communication regardless of the client’s language
B. By providing language-specific APIs
C. By integrating translation services directly into the Hub
D. By configuring language settings in the client-side code
Answer: A

What is the HubLifetimeManager used for in SignalR?
A. To manage the lifetime of Hub instances and handle scaling across multiple servers
B. To configure Hub methods
C. To handle client-side script integration
D. To manage database connections
Answer: A

How do you handle client-side errors in a SignalR application?
A. By using JavaScript error handling mechanisms and catch blocks in SignalR methods
B. By configuring server-side error handling only
C. By using try-catch in Hub methods
D. By configuring error logging on the server
Answer: A

What is the role of HubPipelineModule in SignalR?
A. To allow for custom processing of incoming and outgoing messages in the Hub
B. To handle connection management
C. To manage Hub state
D. To configure authentication
Answer: A

How do you enable SignalR logging in an ASP.NET Core application?
A. By configuring logging services in the Startup class and setting log levels for SignalR
B. By using a custom logging library
C. By enabling debug mode in SignalR
D. By adding logging code directly in the Hub
Answer: A

Which SignalR method is used to send a message to all clients except the caller?
A. Clients.AllExcept().SendAsync()
B. BroadcastMessageExcept()
C. SendToOthers()
D. ExcludeSender().Send()
Answer: A

What is IHub in SignalR?
A. The base interface for creating a Hub in SignalR
B. A connection management interface
C. A client-side library for SignalR
D. An authentication interface
Answer: A

How can you implement SignalR with a custom transport layer?
A. By implementing custom transport classes and integrating them with SignalR
B. By configuring the transport layer in the Startup class
C. By using default SignalR transport options only
D. By modifying client-side transport settings
Answer: A

What is the role of IHubCallerContext in SignalR?
A. To provide context information for the caller, such as connection ID and user information
B. To handle Hub state
C. To manage client-side methods
D. To configure server-side settings
Answer: A

How do you ensure that SignalR communication is secure?
A. By using HTTPS, authentication, and authorization mechanisms
B. By encrypting messages manually
C. By using public and private keys
D. By configuring client-side security settings only
Answer: A