为什么此代码返回“不支持指定的方法”。
using System;
using System.IO;
using System.Security.Cryptography;
using System.Web.Mvc;
public class ETagAttribute : ActionFilterAttribute
{
private string GetToken(Stream stream) {
MD5 md5 = MD5.Create();
byte [] checksum = md5.ComputeHash(stream);
return Convert.ToBase64String(checksum, 0, checksum.Length);
}
public override void OnResultExecuted(ResultExecutedContext filterContext)
{
filterContext.HttpContext.Response.AppendHeader("ETag", GetToken(filterContext.HttpContext.Response.OutputStream));
base.OnResultExecuted(filterContext);
}
}
Run Code Online (Sandbox Code Playgroud)
这应该有效,但不是。
显然微软覆盖了 System.Web.HttpResponseStream.Read(Byte[] buffer, Int32 offset, Int32 count) 以便它返回“不支持指定的方法。”,不知道为什么他们会这样做,因为它继承了系统。 IO.Stream 基类...
堆栈跟踪:
[NotSupportedException: Specified method is not supported.]
System.Web.HttpResponseStream.Read(Byte[] buffer, Int32 offset, Int32 count) +29
ETagAttribute.ReadFully(Stream input) in Filters\ETagAttribute.cs:11
ETagAttribute.GetToken(Stream stream) in Filters\ETagAttribute.cs:22
ETagAttribute.OnResultExecuted(ResultExecutedContext …Run Code Online (Sandbox Code Playgroud) 我有一个问题,如果你请帮助我,我有一个错误
必须声明标量变量"@Deitails".
我不知道这个问题是什么,因为我不知道Scalar是什么
var sqlCon = new
SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
// GET CONFERENCE ROLE ID
SqlCommand cmd = new SqlCommand();
cmd.Connection = sqlCon;
cmd.CommandText = "select Conference_Role_ID from AuthorPaper
where Paper_ID = @PaperId";
cmd.Parameters.AddWithValue("@PaperId",
paperId);
cmd.Connection.Open();
string ConferenceRoleId = cmd.ExecuteScalar().ToString();
cmd.Connection.Close();
cmd.Dispose();
string query2 = @"insert into
ReviewPaper(Overall_Rating,Paper_id,Conference_role_id,Deitails)
values(0,@paperId,@ConferenceRoleId,@Deitails);select
SCOPE_IDENTITY() as RPID";
cmd = new SqlCommand(query2, sqlCon);
cmd.Parameters.AddWithValue("@paperId",
paperId);
cmd.Parameters.AddWithValue("@ConferenceRoleId",
ConferenceRoleId);
string ReviewPaperId;
try
{
cmd.Connection.Open();
ReviewPaperId = cmd.ExecuteScalar().ToString();
cmd.Connection.Close();
}
catch (Exception ee) { throw ee; }
finally { cmd.Dispose(); } …Run Code Online (Sandbox Code Playgroud)