请帮助我在'/'应用程序中收到错误“服务器错误”。 HTTP错误400 - 错误请求。 [英] Kindly help iam getting error "Server Error in '/' Application. HTTP Error 400 - Bad Request."
本文介绍了请帮助我在'/'应用程序中收到错误“服务器错误”。 HTTP错误400 - 错误请求。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Data;
namespace Centaurus_Cineplex
{
public partial class Add_Trailor : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
byte[] buffer;
SqlConnection connection;
protected void btn_add_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile && FileUpload1.PostedFile != null
&& FileUpload1.PostedFile.FileName != "")
{
HttpPostedFile file = FileUpload1.PostedFile;
//retrieve the HttpPostedFile object
buffer = new byte[file.ContentLength];
int bytesReaded = file.InputStream.Read(buffer, 0,
FileUpload1.PostedFile.ContentLength);
if (bytesReaded > 0)
{
try
{
connection = new SqlConnection("Data Source=RABIANOUREEN-PC\\SQLEXPRESS;Initial Catalog=Cineplex;Integrated Security=True");
SqlCommand cmd = new SqlCommand
("INSERT INTO Videos (Video, Video_Name, Video_Size)" +
" VALUES (@video, @videoName, @videoSize)", connection);
cmd.Parameters.Add("@video",
SqlDbType.VarBinary, buffer.Length).Value = buffer;
cmd.Parameters.Add("@videoName",
SqlDbType.NVarChar).Value = FileUpload1.FileName;
cmd.Parameters.Add("@videoSize",
SqlDbType.BigInt).Value = file.ContentLength;
using (connection)
{
connection.Open();
// int i = cmd.ExecuteNonQuery();
cmd.ExecuteReader();
Result.Text = "uploaded";
}
}
catch (Exception ex)
{
Result.Text = ex.Message.ToString();
}
finally
{
connection.Close();
}
}
//Response.Redirect(Request.Url.AbsoluteUri);
}
else
{
Result.Text = "Choose a valid video file";
}
}
}
}
推荐答案
你需要允许大文件通过将文件大小值分配给maxRequestLength
属性httpRuntime
标记。
参见设置Web.config以允许ASP .NET应用程序上载大文件 [ ^ ]
You need to allow large files by assigning file size value tomaxRequestLength
property ofhttpRuntime
Tag.
See Setting up Web.config to allow uploading of large files by ASP .NET applications[^]
这篇关于请帮助我在'/'应用程序中收到错误“服务器错误”。 HTTP错误400 - 错误请求。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文