【问题标题】:Security and SQL injection in Sql Server with ASP membership具有 ASP 成员资格的 Sql Server 中的安全性和 SQL 注入
【发布时间】:2014-12-13 15:33:10
【问题描述】:

我正在实施具有成员资格的 ASP MVC。该网站托管在 Azure 云中。

有哪些预防措施可以预防

  1. Sql 注入暴力攻击
  2. 如何根据尝试阻止/锁定用户访问 IP

【问题讨论】:

    标签: asp.net security sql-injection


    【解决方案1】:

    我有第一个问题的答案。 您必须在“Session[data]”中存储一些有用的数据,并且不要从客户端发送。

        public ActionResult Index()
        {
            try
            {
                if (WebSecurity.IsAuthenticated)
                {
                    String ContractID_string = Session["ContractID"].ToString();
                    if(ContractID_string!="0") 
    

    也不要在没有检查的情况下在 linq 或 sqlQuery 中使用来自客户端的某些字符串输入值。

    最好的使用方法

    控制

     [HttpPost]
        [ValidateAntiForgeryToken]
    public ActionResult _SaveMail(Email_Options Mail)
    

    在视图中

         @using (Ajax.BeginForm("_SaveMail", "Contract", Model,
            new AjaxOptions
            {
                UpdateTargetId = "Email_Options",
                OnFailure = "alert('errr')",
                OnSuccess = "DeleteErrorMessage('#Form_"+ViewBag.Contract_part+"')"
            }, htmlAttributes: new { id = "Form_"+ViewBag.Contract_part}))
        {
            @Html.AntiForgeryToken()
            @Html.ValidationSummary()
            <table id="Email_Options">
                <tbody>
                    <tr>
                        <th>@Html.LabelFor(m => Model.Email, new { style = "font-size:1.05em;" })</th>
                        <th> 
                            @Html.HiddenFor(m => Model.ContractID)
                            @Html.EditorFor(m => Model.Email)
                            @Html.ValidationMessageFor(m => Model.Email)
                            <button style="font-size:1em; margin:0px; padding:0;" type="submit">Сохранить</button>
                        </th>
                    </tr>
                    <tr>
                        <th>@Html.LabelFor(m => Model.SendToEmail, new { @class = "checkbox" })</th>
                        <th>@Html.CheckBoxFor(m => Model.SendToEmail)</th>
                    </tr>
                    <tr>
                        <th>@Html.LabelFor(m => Model.SentToHome, new { @class = "checkbox" })</th>
                        <th>@Html.CheckBoxFor(m => Model.SentToHome)</th>
                    </tr>
                    <tr>
                        <th>@Html.LabelFor(m => Model.Print, new { @class = "checkbox" })</th>
                        <th>@Html.CheckBoxFor(m => Model.Print)</th>
                    </tr>
                </tbody>
            </table>
        }    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-21
      • 2013-03-04
      • 1970-01-01
      相关资源
      最近更新 更多