我使用以下代码将文件附加到电子邮件中.
msg = new MailMessage();
using (strMem = new MemoryStream((byte[])attDr["filedata"]))
{
using (strWriter = new StreamWriter(strMem))
{
strWriter.Flush(); strMem.Position = 0;
using (attachment = new Attachment(strMem, attDr["filename"].ToString()))
{
msg.Attachments.Add(attachment);
}
}
}
...
...
msg.Send(); //Error: System.ObjectDisposedException: Cannot access a closed Stream.
Run Code Online (Sandbox Code Playgroud)
错误消息是://错误:System.ObjectDisposedException:无法访问已关闭的Stream
我猜测"USING"语句在退出块时关闭流.但为什么"Attacments.Add()"没有制作自己的流副本?
在删除一些过时的代码时,我遇到了一个意想不到的情况,重新创建如下:
class Program
{
static void Main(string[] args)
{
ViableMethod();
Console.WriteLine("");
SoftDeprecatedMethod();//Compiler warning
//HardDeprecatedMethod();//Can't call that from here, compiler error
Console.ReadKey(true);
}
public static void ViableMethod ()
{
Console.WriteLine("ViableMethod, calls SoftDeprecatedMethod");
SoftDeprecatedMethod();//Compiler warning
//HardDeprecatedMethod();//Can't call that from here, compiler error
}
[Obsolete("soft", false)]
public static void SoftDeprecatedMethod()
{
Console.WriteLine("SoftDeprecatedMethod, calls HardDeprecatedMethod");
HardDeprecatedMethod();
}
[Obsolete("hard", true)]
public static void HardDeprecatedMethod()
{
Console.WriteLine("HardDeprecatedMethod");
}
}
Run Code Online (Sandbox Code Playgroud)
基于输出,似乎允许使用警告弃用的函数调用已弃用的函数,并且代码将执行.
我的期望是我会看到编译器错误抱怨不允许调用HardDeprecatedMethod()from SoftDeprecatedMethod().观察到的行为对我来说似乎很奇怪.
有谁知道这是否是所期望的行为(如果是,为什么),或者这可能是[Obsolete]属性实现中的缺陷?
将System.Data.Entity组合添加到我的Web配置后,我遇到了这个错误:使用注册为allowDefinition ='MachineToApplication'的部分超出应用程序级别是错误的.此错误可能是由于未在IIS中将虚拟目录配置为应用程序引起的.
我删除了obj和bin文件夹,我删除了行身份验证="windows",尝试重新打开,因为有人说它有效,我检查了主文件夹中只有1个web.config(实体框架 - 文件夹形式,型号,DAL和BLL)......
还有什么其他原因会发生这种情况?我到处搜索,这基本上是我发现的上述原因....
这是我的web.config,如果它有所不同:
<configuration>
<connectionStrings>
<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
<add name="CStringVKB" connectionString="Data Source=.;Initial Catalog=VKB;Persist Security Info=True;User ID=websiteservice;Password=websiteservice" providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<compilation debug="true" optimizeCompilations="true" targetFramework="4.0" >
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
<!--<authentication mode="Windows">
<forms loginUrl="~/Account/Login.aspx" timeout="2880" />
</authentication>-->
<membership>
<providers>
<clear/>
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices"
enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
applicationName="/" />
</providers>
</membership>
<profile>
<providers>
<clear/>
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
</providers>
</profile>
<roleManager …Run Code Online (Sandbox Code Playgroud) 我有一个C#表单应用程序,使用串行端口连接到电子设备.类"'SerialCommunicationManager'"在应用程序启动时连接到串行端口,并处理与设备通信的脏事.
我想要的是暴露以下方法.
主要是在同一台机器上运行的本地网站是我想要公开方法的网站,但是在未来我想象也需要外部应用程序.
公开功能的最简单方法是什么?
十分感谢
//大卫

我正在关注如何为WCF服务实现用户名身份验证的MSDN文章.
在步骤5中,attribute: [AspNetCompatibilityRequirements]在服务上设置a以为ASP.NET兼容模式配置WCF服务.这是必需的,因为身份验证由HTTP模块完成,您必须能够从HTTP上下文获取主体和身份,以便在WCF中以命令性或声明性方式授权用户.
当我运行该服务时,我收到此错误消息:
无法激活该服务,因为它不支持ASP.NET兼容性.为此应用程序启用了ASP.NET兼容性.在web.config中关闭ASP.NET兼容模式,或者将AspNetCompatibilityRequirements属性添加到服务类型,其RequirementsMode设置为"Allowed"或"Required".
看起来即使我明确声明了它被忽略的属性.这可能是什么原因?即使我将值更改为AspNetCompatibilityRequirementsMode.Allowed它也不起作用.同样的错误消息是因为IIS没有理由抱怨!
服务:
namespace MyNamespace.IISServiceHost
{
[ServiceBehavior(MaxItemsInObjectGraph = int.MaxValue)]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
public class CompanyNameAPIService
{
public CompanyNameAPIService()
{
}
}
}
Run Code Online (Sandbox Code Playgroud)
接口
namespace MyNamespace
{
[ServiceContract]
public interface ICompanyAPI
{
[OperationContract]
[PrincipalPermission(SecurityAction.Demand, Role="WSIuser")]
[ServiceKnownType(typeof(Supplier))]
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
void AddUpdateSuppliers(int companyId, Supplier[] sups);
[OperationContract]
[PrincipalPermission(SecurityAction.Demand, Role = "WSIuser")]
[ServiceKnownType(typeof(Dimension))]
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
void …Run Code Online (Sandbox Code Playgroud) 我正在尝试找出根据标记构建HTML向下钻取表的最佳方法.它需要简单但最重要的是它应该是合乎逻辑的.
有没有关于如何做到这一点的首选标准?你会推荐什么?
一种可能的解决方案是' colspan '.
<tbody>
<tr><td> + </td><td>Summery row 1</td><td>Summery row 1</td></tr>
<tr><td> + </td><td>Summery row 2</td><td>Summery row 2</td></tr>
<tr style=hidden><td colspan=3>drilldown data goes here...</td></tr>
</tbody>
Run Code Online (Sandbox Code Playgroud)
另一种解决方案是' tbody ':
<tbody>
<tr><td> + </td><td>Summery row 1</td><td>Summery row 1</td></tr>
<tr><td> + </td><td>Summery row 2</td><td>Summery row 2</td></tr>
</tbody>
<tbody id=DrilldownDataOfRow2 style=hidden>
<tr><td></td><td>drilldown data goes here...</td></tr>
</tbody>
Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个函数,检查价格是否有折扣,如果它确实应该输出一个计算值,但我似乎无法让它工作.谁知道我做错了什么?
ASP.NET :(从DB中提取正在按预期工作)
<%# DiscountFunction(Eval("status"), Eval("price"), Eval("procent"))%>
Run Code Online (Sandbox Code Playgroud)
代码背后:
public string DiscountFunction(string status, string price, string discount)
{
if(status == "True") {
int price2 = Convert.ToInt32(price);
int discount2 = Convert.ToInt32(discount);
int calc = (price2 / 100) * discount2;
int final_calc = pris2-calc;
return price + " " + final_calc;
} else {
return price.ToString();
}
}
Run Code Online (Sandbox Code Playgroud)
我收到错误,我的函数包含无效的参数.
我有两个ToolStripCombobox控件,每个控件都有SelectedIndexChanged附加了侦听器。
当我以编程方式修改项目集合时遇到问题。我最终不情愿地触发了 SelectedIndexChanged 。
当在线搜索解决方案时,我发现了OnSelectionChangeComfilled和相应的事件,但 Visual studio 说:
'System.Windows.Forms.ToolStripComboBox.OnSelectionChangeCommitted(System.EventArgs)' is inaccessible due to its protection level.
Run Code Online (Sandbox Code Playgroud)
如果无法利用SelectionChangeCommitted,还有什么其他方法可以避免手动更新 ToolStripComboBox 项时触发事件?
我使用 .Net 4.0 并且ToolStripComboBox配置了DropDownStyle = DropDownList.
我试图理解ASP经典如何在内部处理字符串.我用谷歌搜索和调试,但我仍然不知道如何在ASP脚本中编码字符串.
请参见下图.
输入数据是否已转换,以便所有字符串变量具有相同的编码,无论哪个源?
大多数ASP页面都以utf-8的形式保存在磁盘上.但它们确实#include使用其他编码保存的asp文件.在前端页面的顶部,我将响应编码设置为unicode.
response.codepage = 65001 //unicode
reponse.charset = 'utf-8'
Run Code Online (Sandbox Code Playgroud)
这可能很容易,但对于我的生活,我似乎无法弄明白.这是我的表:
uid | userID | trackID | carID | highscoreDate | highscore
-----------------------------------------------------------------
1 1 1 1 [date] 123
2 1 1 1 [date] 44
3 2 2 1 [date] 222
4 2 1 1 [date] 28
5 1 2 1 [date] 17
Run Code Online (Sandbox Code Playgroud)
我想获得的SUM的最高为每个用户和轨道高分.在上面的数据中,将给出:
user 1: 140
user 2: 250
Run Code Online (Sandbox Code Playgroud) c# ×6
.net ×4
asp.net ×3
asp-classic ×1
attributes ×1
directory ×1
email ×1
encoding ×1
html ×1
html-table ×1
innodb ×1
mysql ×1
sql ×1
tcp ×1
virtual ×1
wcf ×1
web-services ×1
winforms ×1