Zum umleiten auf die login-Seite von einem web service in einem AJAX-call?

Bin ich mit dem jQuery-Aufruf web service (*.asmx -) Methoden. Der web-service-FormsAuthentication verwendet, um zu bestimmen, ob der aufrufende Benutzer authentifiziert ist. Ich bin nicht in der Lage, um wieder eine redirect-status code aus der web-Methode, z.B.

[WebMethod(EnableSession=true)]
public Dictionary<string, object> GetArchivedFiles(int pageSize, int page)
{
    if(HttpContext.Current.User.Identity.IsAuthenticated && Session["UserId"] != null)
        //Do some computing and return a Dictionary.       

    //Method will fall through here if the user is not authenticated.
    HttpContext.Current.Response.StatusCode = (int) HttpStatusCode.Unauthorized;
    return null;
}

Den redirect funktioniert nicht, ich bekomme immer 500 Internal Server Error, wenn dies zu tun. Ich habe versucht, verschiedene codes. Was wäre die empfohlene Art und Weise, hier zu gehen? Ich Lesen müssen, das umleiten von Informationen aus JavaScript und laden die Seite neu (oder vielleicht die Anzeige eines login-Steuerung AJAX-Weg).

Ich tatsächlich bekommen ein JSON-Objekt zurück, das wie folgt aussieht:

{"Message":"Authentication failed.","StackTrace":null,"ExceptionType":"System.InvalidOperationException"
}

Ich habe versucht mit dem debugger, aber es nicht zeigen, dass alle Methoden eingetragen sind. Wie Sie sehen können, der StackTrace ist null...

Wenn Sie angerufen werden, in Fiddler als standard-POST-Anforderung (nicht XMLHttpRequest) es gibt eine Ausnahme tatsächlich:

HTTP/1.1 500 Internal Server Error
Server: ASP.NET Development Server/9.0.0.0
Date: Wed, 04 Mar 2009 14:46:02 GMT
X-AspNet-Version: 2.0.50727
Cache-Control: private
Content-Type: text/plain; charset=utf-8
Content-Length: 1739
Connection: Close

System.NotSupportedException: The type System.Collections.Generic.Dictionary`2[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Object, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] is not supported because it implements IDictionary.
   at System.Xml.Serialization.TypeScope.GetDefaultIndexer(Type type, String memberInfo)
   at System.Xml.Serialization.TypeScope.ImportTypeDesc(Type type, MemberInfo memberInfo, Boolean directReference)
   at System.Xml.Serialization.TypeScope.GetTypeDesc(Type type, MemberInfo source, Boolean directReference, Boolean throwOnError)
   at System.Xml.Serialization.ModelScope.GetTypeModel(Type type, Boolean directReference)
   at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(Type type, XmlRootAttribute root, String defaultNamespace)
   at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(Type type, XmlRootAttribute root)
   at System.Web.Services.Protocols.XmlReturn.GetInitializers(LogicalMethodInfo[] methodInfos)
   at System.Web.Services.Protocols.XmlReturnWriter.GetInitializers(LogicalMethodInfo[] methodInfos)
   at System.Web.Services.Protocols.MimeFormatter.GetInitializers(Type type, LogicalMethodInfo[] methodInfos)
   at System.Web.Services.Protocols.HttpServerType..ctor(Type type)
   at System.Web.Services.Protocols.HttpServerProtocol.Initialize()
   at System.Web.Services.Protocols.ServerProtocol.SetContext(Type type, HttpContext context, HttpRequest request, HttpResponse response)
   at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)
Schreibe einen Kommentar