在我的测试完成后,我总是得到以下异常,并且测试运行器正在关闭.这是正常的吗?当我得到一堆随机异常时,我总是感到很担心..
线程''(0xc04)已退出代码0(0x0).
System.ServiceModel.dll中发生'System.ComponentModel.Win32Exception'类型的第一次机会异常
mscorlib.dll中出现'System.Threading.ThreadAbortException'类型的第一次机会异常
System.Transactions Critical:0:http://msdn.microsoft.com/TraceCodes/System/ActivityTracing/2004/07/Reliability/Exception/Unhandled Unhandled exceptionvstest.executionengine.exeSystem.AppDomainUnloadedException,mscorlib,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089尝试访问已卸载的AppDomain.System.AppDomainUnloadedException:尝试访问已卸载的AppDomain.
线程''(0xdd8)已经退出代码0(0x0).
'vstest.executionengine.exe'(Managed(v4.0.30319)):已加载'C:\ PROGRAM FILES(X86)\ MICROSOFT VISUAL STUDIO 11.0\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\TESTWINDOW\Extensions\CppUnitFramework\Microsoft.VisualStudio. TestTools.CppUnitTestFramework.TestEngine.dll''vstest.executionengine.exe'(托管(v4.0.30319)):已加载'C:\ PROGRAM FILES(X86)\ MICROSOFT VISUAL STUDIO 11.0\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\TESTWINDOW \扩展\ CppUnitFramework\Microsoft.VisualStudio.TestTools.CppUnitTestFramework.Discoverer.dll"
线程''(0xa64)已退出,代码为0(0x0).
Microsoft.VisualStudio.TestPlatform.TestExecutor.Core.dll中出现"System.InvalidOperationException"类型的第一次机会异常
System.ServiceModel.dll中发生了'System.ServiceModel.CommunicationObjectAbortedException'类型的第一次机会异常
等等
我正在尝试调整我使用FileUpload控件上传的jpg图像,并在将其保存到数据库(SQL Server 2008)之前将其转换为byte(varbinary(MAX)).我所做的和下面的代码显示我设法将其转换为字节并作为varbinary(MAX)保存到数据库中.我想知道如何在完成所有这些功能之前调整图像大小.帮帮我吧 谢谢!
阅读文件
string filePath = FileUpload1.PostedFile.FileName;
string filename = Path.GetFileName(filePath);
string ext = Path.GetExtension(filename);
Run Code Online (Sandbox Code Playgroud)
根据文件扩展名设置contenttype
string contenttype = String.Empty;
switch (ext)
{
case ".jpg":
contenttype = "image/jpg";
break;
}
Run Code Online (Sandbox Code Playgroud)
转换为字节并使用varbinary保存到数据库中
if (contenttype != String.Empty)
{
Stream fs = FileUpload1.PostedFile.InputStream;
BinaryReader br = new BinaryReader(fs);
Byte[] bytes = br.ReadBytes((Int32)fs.Length);
//insert the file into database
string strQuery = "insert into MemberReport(username, typeofcrime, location, crdatetime, citizenreport, image1, image2, image3, image4, image5)" +
" values ('" + username + "','" + …Run Code Online (Sandbox Code Playgroud) 我对ASP.Net MVC有点新意,但我想了解何时以及如何最好地使用ViewModels.
在我的许多视图中,所需的数据仅部分位于一个模型中.为此,我使用AutoMapper将Model映射到ViewModel,然后将ViewModel传递给View.
但是,在其他视图中,需要来自多个模型的数据.
到目前为止,我实现这一目标的方式是这样的:
public class GamesEditData
{
public Game Game { get; set; }
public ICollection<Genre> Genres { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
... 游戏和流派是模特.我觉得我在这里做错了,因为这是直接将模型本身传递给View.这与我从单独的ViewModel传递属性的其他时间不同,这让我觉得我打破了某种模式.
简而言之,在ASP.Net MVC中使用ViewModel设计模式在多个模型中填充View的最佳方法是什么?
我正在尝试将OAuth注册/登录集成到我的ASP.NET MVC 4站点中.我登录后无法获取用户的ID和/或用户名.登录时,我有:
AuthenticationResult result = OAuthWebSecurity.VerifyAuthentication(Url.Action("ExternalLoginCallback", new { ReturnUrl = returnUrl }));
if(result.IsSuccessful)
{
if(OAuthWebSecurity.Login(result.Provider, result.ProviderUserId, createPersistentCookie: false))
{
string username = User.Identity.Name;
int userID = WebSecurity.CurrentUserId;
}
}
Run Code Online (Sandbox Code Playgroud)
虽然OAuthWebSecurity.Login成功(返回true),但username设置为空字符串,userID设置为-1(这意味着没有人登录).任何人都可以帮助解释登录函数返回true之间的这种差异,但这两种确定当前用户的方式另有说法吗?或者也许告诉我一种在OAuth登录后找到UserId(对应于UserProfile表)的方法?
此登录结构主要来自启动MVC 4 Internet应用程序时提供的默认成员身份代码.
c# ×3
asp.net ×1
asp.net-mvc ×1
file-upload ×1
oauth ×1
sql-server ×1
unit-testing ×1
varbinarymax ×1