在jQuery中使用JSONP时是否可以捕获错误?我已经尝试了$ .getJSON和$ .ajax方法,但都没有捕获我正在测试的404错误.这是我尝试过的(请记住,这些都可以成功运行,但我想在失败时处理这种情况):
jQuery.ajax({
type: "GET",
url: handlerURL,
dataType: "jsonp",
success: function(results){
alert("Success!");
},
error: function(XMLHttpRequest, textStatus, errorThrown){
alert("Error");
}
});
Run Code Online (Sandbox Code Playgroud)
并且:
jQuery.getJSON(handlerURL + "&callback=?",
function(jsonResult){
alert("Success!");
});
Run Code Online (Sandbox Code Playgroud)
我也尝试添加$ .ajaxError,但这也不起作用:
jQuery(document).ajaxError(function(event, request, settings){
alert("Error");
});
Run Code Online (Sandbox Code Playgroud)
在此先感谢您的回复!
是否可以使用C#读取.PST文件?我想将此作为一个独立的应用程序,而不是作为Outlook插件(如果可能的话).
如果已经看到类似于提及MailNavigator的其他 SO 问题 ,但我希望在C#中以编程方式执行此操作.
我查看了Microsoft.Office.Interop.Outlook命名空间,但它似乎只适用于Outlook插件.LibPST似乎能够读取PST文件,但这是在C中(对不起Joel,我毕业前没有学过C).
任何帮助将不胜感激,谢谢!
编辑:
谢谢大家的回复!我接受了Matthew Ruston的回答作为答案,因为它最终导致我找到了我正在寻找的代码.这是我工作的一个简单示例(您需要添加对Microsoft.Office.Interop.Outlook的引用):
using System;
using System.Collections.Generic;
using Microsoft.Office.Interop.Outlook;
namespace PSTReader {
class Program {
static void Main () {
try {
IEnumerable<MailItem> mailItems = readPst(@"C:\temp\PST\Test.pst", "Test PST");
foreach (MailItem mailItem in mailItems) {
Console.WriteLine(mailItem.SenderName + " - " + mailItem.Subject);
}
} catch (System.Exception ex) {
Console.WriteLine(ex.Message);
}
Console.ReadLine();
}
private static IEnumerable<MailItem> readPst(string pstFilePath, string pstName) {
List<MailItem> mailItems …Run Code Online (Sandbox Code Playgroud) 我已尝试过这篇文章中的建议,但我无法在Vision Studio 2010中使用IIS身份验证进行Windows身份验证.现在我收到以下错误:

这是我的applicationhost.config文件条目:
...
<add name="WindowsAuthenticationModule" lockItem="false" />
...
<authentication>
<anonymousAuthentication enabled="true" userName="" />
<basicAuthentication enabled="false" />
<clientCertificateMappingAuthentication enabled="false" />
<digestAuthentication enabled="false" />
<iisClientCertificateMappingAuthentication enabled="false">
</iisClientCertificateMappingAuthentication>
<windowsAuthentication enabled="true" />
</authentication>
...
<sectionGroup name="authentication">
<section name="anonymousAuthentication" overrideModeDefault="Allow" />
<section name="basicAuthentication" overrideModeDefault="Allow" />
<section name="clientCertificateMappingAuthentication" overrideModeDefault="Allow" />
<section name="digestAuthentication" overrideModeDefault="Allow" />
<section name="iisClientCertificateMappingAuthentication" overrideModeDefault="Allow" />
<section name="windowsAuthentication" overrideModeDefault="Allow" />
</sectionGroup>
Run Code Online (Sandbox Code Playgroud)
我的web.config:
<system.web>
<authentication mode="Windows" />
</system.web>
<system.webServer>
<security>
<authentication>
<anonymousAuthentication enabled="false" />
<windowsAuthentication enabled="true" />
</authentication>
</security>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
这是.NET …
我相信我在这里遗漏了一些明显的东西.当我从OData服务请求JSON响应时,我得到的DateTime属性的结果与我请求XML时的结果不同.我将使用NerdDinner OData feed作为示例.
JSON:
http://www.nerddinner.com/Services/OData.svc/Dinners(1)?$format=json
"EventDate": "\/Date(1235764800000)\/"
Run Code Online (Sandbox Code Playgroud)
XML:
http://www.nerddinner.com/Services/OData.svc/Dinners(1)
<d:EventDate m:type="Edm.DateTime">2009-02-27T20:00:00</d:EventDate>
Run Code Online (Sandbox Code Playgroud)
当我做警报(新日期(1235764800000))时,我得到这个结果:

当我使用LINQPad运行相同的查询时,我也得到了8PM的结果.为什么JSON结果中的时区不正确?似乎假设响应是GMT.我应该在客户端上处理这个(通过javascript)还是我可以在服务器上设置的东西?
我在客户端上使用jQuery,在服务器上使用WCF数据服务(和实体框架).
更新:
我在客户端使用Datejs来处理UTC日期时间格式.我想知道这是否是解决这个问题的正确方法.
function getDateString(jsonDate) {
if (jsonDate == undefined) {
return "";
}
var utcTime = parseInt(jsonDate.substr(6));
var date = new Date(utcTime);
var minutesOffset = date.getTimezoneOffset();
return date.addMinutes(minutesOffset).toString("M/d/yyyy h:mm tt");
}
Run Code Online (Sandbox Code Playgroud) 我正在寻找一种方法来更改Windows(本例中为XP)计算机上的本地用户帐户(本地管理员)的密码.我已经阅读了关于一种方法的CodeProject文章,但这似乎并不"干净".
我可以看到这可能与WMI有关,所以这可能是答案,但我无法弄清楚如何将WinNT WMI命名空间与ManagementObject一起使用.当我尝试以下代码时,它会抛出"无效参数"异常.
public static void ResetPassword(string computerName, string username, string newPassword){
ManagementObject managementObject = new ManagementObject("WinNT://" + computerName + "/" + username); // Throws Exception
object[] newpasswordObj = {newPassword};
managementObject.InvokeMethod("SetPassword", newpasswordObj);
}
Run Code Online (Sandbox Code Playgroud)
有一个更好的方法吗?(我使用的是.NET 3.5)
编辑:感谢Ely指出我正确的方向.这是我最终使用的代码:
public static void ResetPassword(string computerName, string username, string newPassword) {
DirectoryEntry directoryEntry = new DirectoryEntry(string.Format("WinNT://{0}/{1}", computerName, username));
directoryEntry.Invoke("SetPassword", newPassword);
}
Run Code Online (Sandbox Code Playgroud) 我正在开发一个管理Active Directory中的用户帐户的应用程序.我尽可能使用System.DirectoryServices.AccountManagement命名空间,但我无法弄清楚如何确定用户的主要组.当我尝试删除作为用户主要组的组时,我得到一个例外.这是我目前的代码:
private void removeFromGroup(UserPrincipal userPrincipal, GroupPrincipal groupPrincipal) {
TODO: Check to see if this Group is the user's primary group.
groupPrincipal.Members.Remove(userPrincipal);
groupPrincipal.Save();
}
Run Code Online (Sandbox Code Playgroud)
有没有办法获取用户的主要组的名称,以便我可以在尝试从该组中删除用户之前进行一些验证?
是否可以从另一个进程向连接到Hub的客户端发送消息?我设置LINQPad来引用我的Hub项目的DLL并设置VS以将调试附加到LINQPad进程.我的项目有一个HubNotification类,它使用以下代码:
dynamic clients = Hub.GetClients<MyHubClass>();
clients.SendMessage("My Message");
Run Code Online (Sandbox Code Playgroud)
调试时我可以看到这个代码被调用,但我的连接客户端永远不会收到消息.我已经与Fiddler验证了上述代码运行时没有HTTP发生.我错过了什么,或者这是不可能的?
c# ×3
.net-4.0 ×1
c#-3.0 ×1
iis-express ×1
javascript ×1
jquery ×1
json ×1
jsonp ×1
odata ×1
outlook ×1
outlook-2003 ×1
outlook-2007 ×1
pst ×1
signalr ×1
wcf ×1
wmi ×1