我开发了一个基于ASP.NET 4.5和Owin的示例signalR应用程序,
我在IIS 7.5上托管了该应用程序
一切都很好,但我怎么能处理Owin的异常?
请考虑以下代码:
[HubName("SampleHub")]
public class SampleHub : Hub
{
public SampleHub()
{
throw new InvalidOperationException("?!");
}
}
Run Code Online (Sandbox Code Playgroud)
这个异常不会调用Application_Error(这是我的问题)
我在哪里可以获得owin的所有异常用于日志记录和调试目的
应用程序错误 ?
我对这样的事情不感兴趣:
app.UseErrorPage(new ErrorPageOptions()
{
ShowCookies = true,
ShowEnvironment = true,
ShowExceptionDetails = true,
ShowHeaders = true,
ShowQuery = true,
ShowSourceCode = true
});
Run Code Online (Sandbox Code Playgroud)
这对于高级场景来说完全没用,比如asp.net web api和asp.net mvc
用于覆盖目的的OnException方法的动作过滤器要好得多.
提前致谢.
我需要运行我的应用程序,它在IIS和.NET CLR自主机模式下提供一些ASP.NET Web API服务.我开发了基于OWIN的ASP.NET Web API服务,它在两台主机上运行良好.现在我需要这样的东西:
public class OwinContextInfrastructure
{
public static IOwinContext Current
{
get
{
if (HttpContext.Current != null)
{
return HttpContext.Current.GetOwinContext();
}
else
{
// What should I do here ?
return null;
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
在我的应用程序中需要时获取当前的owin上下文.
我的代码在IIS上工作正常,但在.NET Self Host模式下我该怎么办?
我有一个有几个C#项目的应用程序,如下所示
每个Web项目(如CRM.Web)都有自己的"html视图"和"js控制器",还有其他几种类型的静态文件.
为了使部署更容易,我想使用Html5清单.
因此,为了实现跨项目的分离部署,我使用了iframe.因此,随着CRM.Web的变化,客户将获得CRM文件,而无需再次下载Warehouse.Web文件!
脚步:
1-我有一个Web API方法,它返回Web程序集的所有名称,例如CRM.Web和Warehouse.Web
2-我还有另一种Web API方法,它将程序集名称作为参数获取,并返回清单文件内容,该内容指向位于该项目上的文件.
public HttpResponseMessage GetManifestByAssemblyName(String assemblyName)
Run Code Online (Sandbox Code Playgroud)
这里省略代码.
response.Content = new StringContent(manifestBody.ToString(), Encoding.UTF8, "text/cache-manifest");
Run Code Online (Sandbox Code Playgroud)
3-在客户端我为每个程序集创建一个新的iFrame,并将src设置为另一个web api方法,该方法返回html主体,它的清单被分配给返回清单体的WebAPI方法的地址(GetManifestByAssemblyName)
String result = String.Format
(@"<html manifest='{0}'> </html>", "/api/AppManifest/GetManifestByAssemblyName?assemblyName=" + assemblyName + ".manifest");
response.Content = new StringContent(result, UTF8Encoding.Default, "text/html");
Run Code Online (Sandbox Code Playgroud)
iFrames的代码:
var htmlPageUrl = "/api/AppManifest/GetHtmlContainerForManifestByName?assemblyName=" + name;
var iFrame = document.createElement("iFrame");
iFrame.setAttribute("src", htmlPageUrl);
iFrame.setAttribute("sandbox", "allow-same-origin");
iFrame.setAttribute("seamless", "seamless");
document.body.appendChild(iFrame);
Run Code Online (Sandbox Code Playgroud)
当我运行应用程序时,它获取程序集名称,然后创建iFrame,每个iFrame自动获得自己的清单.
但window.applicatioCache.status为0表示它没有缓存.
当我进入资源页面时,我可以看到以下内容:

但是,当我请求其中一个缓存的文件时,请求将不使用缓存.
我知道我的网络工作没有参考,这完全基于我的想法,我知道这里可能会出现一些安全限制,但有没有解决问题的方法?
提前致谢.
然后按Ctrl + S保存文件,并首先阅读 …
我有一个便携式类库,其目标如下:
.NET + Silverlight + WinRT + WinPhone + Android + iOS
WinPhone中不存在"System.ComponentModel.DataAnnotations" namesapce
所以我在代码中无法访问该命名空间
如何像"microsoft bcl portability pack"一样解决这个问题
此包提供对诸如"CallerMemberNameAttribute"之类的属性和类的访问,但在运行时它将这些类映射到它们的等效实现(如果存在).
来自" http://www.nuget.org/packages/Microsoft.Bcl/ ":
这些类型与其后来的版本等效"统一".例如,在.NET Framework 4.5上运行时,运行时将看到此程序包中的IProgress与平台中已有的类型相同.
考虑以下课程:
public class Customer
{
public Int32 Id { get; set; }
public String FirstName { get; set; }
public String LastName { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
考虑以下View模型(在MVVM设计模式中)
public class CustomersManagementViewModel
{
public Command<Customer> RemoveCustomer;
public List<Customer> Customers { get; set; }
CustomersManagementViewModel()
{
Customers = new Customers {
new Customer {},
new Customer {}
}
RemoveCustomer = new Command<Customer>((customerToRemove) => {
// do something with that passed customer
}
}
}
Run Code Online (Sandbox Code Playgroud)
并考虑以下观点:
<Window x:Class="View.CustomersManagementView"
xmlns:vm="clr-namespace:ViewModel;assembly=ViewModel"
Name="CustomersManagement">
<Window.DataContext>
<vm:SmsManagementViewModel /> …Run Code Online (Sandbox Code Playgroud) 我们有asp.net web api odata启用服务,支持各种OData格式,如application/json; odata = fullmetadata
这项服务适用于WCF数据服务客户端和JayData
但是我们的响应似乎与我们的kendo网格dataSource不兼容
我已经调查了响应,这是区别的:
kendoUI网站的演示工作正常有以下响应:
"__count": "91"
Run Code Online (Sandbox Code Playgroud)
响应内容类型是: text/javascript;charset=utf-8
您可以在以下位置查看kendo UI演示示例:
http://demos.kendoui.com/web/grid/index.html
这是我们的回应:
"odata.metadata":"http://localhost:2452/odata/$metadata#VehicleGroups","odata.count":"29","value":[
Run Code Online (Sandbox Code Playgroud)
响应内容类型是: application/json; odata=fullmetadata; charset=utf-8
我可以使用生成所需格式的ODataMediaTypeFormatter吗?或者是否有任何解决方案可以使KendoDataSource与我们当前的响应一起使用?任何其他解决方案表示赞赏
请注意,我们已为KendoDataSource启用了OData type: "odata"
谢谢
我使用 padStart 方法(padLeft)创建了一个字符串值,例如:
"5".padStart(19, "0")
Run Code Online (Sandbox Code Playgroud)
这导致“0000000000000000005”如何使用正则表达式取回那 5 个?我已经测试过这个:
/^0*(\d+)$/.exec(d)[1]
Run Code Online (Sandbox Code Playgroud)
正确返回 5 。
但是这个正则表达式为“00000012.22”之类的东西返回null
样品:
5 > 5
005 > 5
0011.22 > 11.22 >> 这是第一个问题!
00100 >> 100
001001 >> 1001
00.5 >> 0.5这是第二个问题!
工作代码但没有正则表达式:
function toDb(d) {
if (d == null) return null;
var precisionIndex = d.indexOf('.');
return d.toString().padStart((29 + precisionIndex + 1), '0');
}
function fromDb(d) {
if (d == null) return null;
d = d.replace(/^0+/, ''); // I'd like to use regex here
if (d.indexOf('.') == …Run Code Online (Sandbox Code Playgroud) 看看下面的代码:
为什么result1有2个通用参数?
public class Program
{
public static void Main(string[] args)
{
IEnumerable<Test> result1 = Test1();
Console.WriteLine(result1.GetType().GetGenericArguments().Count()); // 2
IEnumerable<Test> result2 = Test2();
Console.WriteLine(result2.GetType().GetGenericArguments().Count()); // 1
}
public static IEnumerable<Test> Test1()
{
return new Test[] { }.Where(t => t.Id > 1).Select(t =>
{
t.Id++;
return t;
});
}
public static IEnumerable<Test> Test2()
{
return new Test[] { }.Where(t => t.Id > 1);
}
}
public class Test
{
public virtual int Id { get; set; }
}
Run Code Online (Sandbox Code Playgroud)