<commit_before>---
title: Using NServiceBus with ASP.NET MVC
summary: Integrating NServiceBus in ASP.NET MVC web applications, to be able to send messages from the website.
tags: []
redirects:
- nservicebus/using-nservicebus-with-asp.net-mvc
related:
- nservicebus/hosting
---

Run the solution. A new browser window/tab opens, as well as a console application.

The web sample starts with two available methods of sending a command to the server and waiting for a response from it:

-   `SendAndBlock`: a controller uses NServiceBus
-   `SendAsync`: an `AsyncController` uses NServiceBus

The sample covers only the sending of the asynchronous message as the send and block are similar in NServiceBus.

NOTE: In `SendAndBlock`, the web page renders synchronously. From the user's perspective, the interaction is synchronous and blocking, even though behind the scenes NServiceBus is messaging asynchronously.

![AsyncPages Asp.Net Mvc sample running](async-pages-mvc-selecting-blocking-method.png "AsyncPages Asp.Net Mvc sample running")

Choosing SendAsync results in the following page: 

![AsyncPages Asp.Net Mvc sample running](async-pages-mvc-running.png "AsyncPages Asp.Net Mvc sample running")

Changing the number in the text box from even to odd changes the result.

Now, look at the code. This sample has three projects:
 
-   `AsyncPlagesMvc`: ASP.NET MVC application that sends messages (found in `Messages` project)<commit_msg>typo; plages<commit_after>---
title: Using NServiceBus with ASP.NET MVC
summary: Integrating NServiceBus in ASP.NET MVC web applications, to be able to send messages from the website.
tags: []
redirects:
- nservicebus/using-nservicebus-with-asp.net-mvc
related:
- nservicebus/hosting
---

Run the solution. A new browser window/tab opens, as well as a console application.

The web sample starts with two available methods of sending a command to the server and waiting for a response from it:

-   `SendAndBlock`: a controller uses NServiceBus
-   `SendAsync`: an `AsyncController` uses NServiceBus

The sample covers only the sending of the asynchronous message as the send and block are similar in NServiceBus.

NOTE: In `SendAndBlock`, the web page renders synchronously. From the user's perspective, the interaction is synchronous and blocking, even though behind the scenes NServiceBus is messaging asynchronously.

![AsyncPages Asp.Net Mvc sample running](async-pages-mvc-selecting-blocking-method.png "AsyncPages Asp.Net Mvc sample running")

Choosing SendAsync results in the following page: 

![AsyncPages Asp.Net Mvc sample running](async-pages-mvc-running.png "AsyncPages Asp.Net Mvc sample running")

Changing the number in the text box from even to odd changes the result.

Now, look at the code. This sample has three projects:
 
-   `AsyncPagesMvc`: ASP.NET MVC application that sends messages (found in `Messages` project)
{'fraction_non_alphanumeric': 0.06701388888888889, 'fraction_numerical': 0.0, 'mean_word_length': 4.6936758893280635, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1548325', 'n_tokens_mistral': 806, 'n_tokens_neox': 756, 'n_words': 366}