Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some markdown language syntax highlights #26680

Merged
merged 1 commit into from
Nov 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions docs/security.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,21 +118,21 @@ Any values supplied in a LINQ query will be appropriately parameterized or escap

For example, the following method looks up customers with a given last name in the database.

```
```cs
public IEnumerable<Customer> FindCustomers(string lastName)
{
using(var context = new CustomerContext())
using (var context = new CustomerContext())
{
var customers = context.Customers
.Where(c => c.LastName == lastName)
.ToList;
.ToList();
}
}
```

The last name value is passed as a parameter because it may come from an end user of the application and be subject to malicious input.

```
```sql
SELECT [c].[CustomerId], [c].[Name]
FROM [Customer] AS [c]
WHERE [c].[LastName] = @p0
Expand All @@ -145,10 +145,10 @@ Any values that come from instance data (i.e. values stored in entity properties
**Example**
For example, the following method creates a new customer in the database based on a supplied first and last name.

```
```cs
public Customer CreateCustomer(string firstName, string lastName)
{
using(var context = new CustomerContext())
using (var context = new CustomerContext())
{
var customer = new Customer
{
Expand All @@ -166,7 +166,7 @@ public Customer CreateCustomer(string firstName, string lastName)

The names values are passed as a parameter because they may come from an end user of the application and be subject to malicious input.

```
```sql
INSERT INTO [Customer] ([FirstName], [LastName])
OUTPUT INSERTED.[CustomerId]
VALUES (@p0, @p1)
Expand All @@ -186,19 +186,19 @@ When using APIs that accept a raw SQL string the API allows values to be easily

For example, the following code makes use of parameters for some end-user supplied strings when executing a raw SQL command against a database. The command is executed by dropping down to the ADO.NET `DbCommand` for the underlying data store.

```
```cs
public void MoveClients(string oldOwner, string newOwner)
{
using (var context = new OrdersContext(str))
using (var context = new OrdersContext())
{
var connection = context.Database.AsRelational().Connection.DbConnection;
var cmd = connection .CreateCommand();
var cmd = connection.CreateCommand();
cmd.CommandText = "UPDATE [dbo].[Customer] SET [Owner] = @p0 WHERE [Owner] = @p1";
cmd.Parameters.Add(new SqlParameter("p0", "newOwner"));
cmd.Parameters.Add(new SqlParameter("p1", "oldOwner"));
connection .Open();
cmd.Parameters.Add(new SqlParameter("p0", newOwner));
cmd.Parameters.Add(new SqlParameter("p1", oldOwner));
connection.Open();
cmd.ExecuteNonQuery();
connection .Close();
connection.Close();
}
}
```
Expand Down