This repository was archived by the owner on May 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
826e8be
commit ad714cd
Showing
6 changed files
with
97 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using System; | ||
using System.Data; | ||
using System.Text; | ||
using Microsoft.Data.SqlClient; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace SecurityTest | ||
{ | ||
public class Class1Options | ||
{ | ||
public string ConnectionString { get; set; } | ||
} | ||
|
||
public class Class1 | ||
{ | ||
private readonly ILogger<Class1> logger; | ||
private readonly IOptions<Class1Options> options; | ||
|
||
public Class1(ILogger<Class1> logger, IOptions<Class1Options> options) | ||
{ | ||
this.logger = logger; | ||
this.options = options; | ||
} | ||
|
||
public void Method1(string title, string contents, string user) | ||
{ | ||
var connection = new SqlConnection(); | ||
var sb = new StringBuilder(); | ||
try | ||
{ | ||
connection.ConnectionString = options.Value.ConnectionString; | ||
connection.Open(); | ||
var insertSql = | ||
string.Format("insert into BlogEntries (Title, Contents, Author, PostedDate) values ('{0}','{1}','{2}',{3:yyyy-MM-dd}); select top 1 * from blogentries order by Id desc;", | ||
title, | ||
contents, | ||
user, | ||
DateTime.Now); | ||
|
||
var insertCommand = new SqlCommand(insertSql, connection); | ||
|
||
var dataReader = insertCommand.ExecuteReader(); | ||
|
||
while (dataReader.Read()) { | ||
var x = string.Format("Id:<br />{0}<br />Title:<br />{1}<br />Contents:<br />{2}<br />Author:<br />{3}<br />Posted date:<br />{4}<br />", | ||
dataReader[0], | ||
dataReader[1], | ||
dataReader[2], | ||
dataReader[3], | ||
dataReader[4]); | ||
sb.AppendLine(x); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
logger.LogError(string.Format("A problem has occured. Please try again. Error={0}", ex.Message)); | ||
} | ||
finally | ||
{ | ||
if (connection.State == ConnectionState.Open) | ||
{ | ||
connection.Close(); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.7" /> | ||
<PackageReference Include="Microsoft.Data.SqlClient" Version="2.0.0" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...odules/SimplCommerce.Module.StorageAzureBlob/SimplCommerce.Module.StorageAzureBlob.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters