나는 다음과 같은 방법으로 Web 서비스가 작동하지 않습니다C#하는 SqlCommand는
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
[WebMethod]
public string Login(string passwort, string email, string firma)
{
return LoginHelper.Login(passwort, email, firma);
}
내 LoginHelper 코드 : 내 질문을 편집 한
그 도움 얘들 아에 대한
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
namespace WebService1
{
public class LoginHelper
{
public static string Login(string passwort, string email, string firma)
{
string userName = "";
SqlConnection con = new SqlConnection(@"Data Source=Yeah-PC\SQLEXPRESS;Initial Catalog=works;Integrated Security=true;");
SqlCommand cmd = new SqlCommand(@"SELECT firma FROM TestData
WHERE email = @email", con);
cmd.Parameters.AddWithValue("@email", email);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
//userName += dr["email"].ToString();
//userName += dr["passwort"].ToString();
userName += dr["firma"].ToString();
}
dr.Close();
con.Close();
return userName;
}
}
}
감사합니다. 그 해결책은 지금 안전합니까? 나는 SQL-Injection을 반대한다. 내가 더 잘할 수있는 것이 더 있니?
가장 먼저 잘못된 것은 SQL 문자열을 연결하는 것입니다. 대신 쿼리 매개 변수를 사용해야합니다. – David
이를 위해 매개 변수화 된 SQL을 사용해야합니다. 현재 작성된 코드는 SQL 주입 공격에 취약합니다. 나는 그 변화를 먼저 만들 것이다. 그렇게 할 때 문제가 사라질 가능성이 있습니다. –
또한 SqlConnection, SqlCommand 및 SqlDataReader를'using' 블록에 넣지 않고 있으며 선택의 여지가없는 한 WCF를 사용해야 할 때 ASMX 웹 서비스를 사용하고 있습니다. –