2016-03-24 11 views
3

Service Stackを使用して小さなWebサイトを作成しましたが、ユーザーのアップロードに問題があります。私たちは、ユーザーがセッションを閉じたPOSTを使ってファイルをアップロードすると、それがわかります。ファイルアップロード後にサービススタックセッションが失われる

ファイルのサイズは問題ではないようで、アップロードPOSTに応答するのに遅延はありません。

アップロード前とアップロード後にブラウザが同じセッションID(ss-id)Cookieを送信していることを確認しました。

は、ここでは、AAAを処理している方法は次のとおりです。

public override void Configure(Container container) 
{ 
    //Config examples 
    //this.Plugins.Add(new PostmanFeature()); 
    //this.Plugins.Add(new CorsFeature());    
    ServiceStack.Text.JsConfig.DateHandler = ServiceStack.Text.DateHandler.ISO8601; 

    Plugins.Add(new AuthFeature(() => new AuthUserSession(), 
     new IAuthProvider[] { 
      new FeedPartnerAuthProvider(), //Custom MSSQL based auth 
     } 
    )); 

    //Global response filter to extend session automatically 
    this.GlobalResponseFilters.Add((req, res, requestDto) => 
    { 
     var userSession = req.GetSession(); 
     req.SaveSession(userSession, slidingExpiryTimeSpan); 
    }); 

    this.Plugins.Add(new RazorFormat()); 
} 

はここでアップロードコードは次のようになります。成功し

//Upload Test Models 
[Route("/upload", "POST")] 
public class PostUpload : IReturn<PostUploadResponse> 
{ 
    public String Title { get; set; } 
} 
public class PostUploadResponse 
{ 
    public String Title { get; set; } 
    public Boolean Success { get; set; } 
} 

//Upload Test Service 
[Authenticate] 
public object Post(PostUpload request) 
{ 
    string uploadPath = "~/uploads"; 
    Directory.CreateDirectory(uploadPath.MapAbsolutePath()); 

    var customerFile = Request.Files.SingleOrDefault(uploadedFile => 
     uploadedFile.ContentLength > 0 && 
     uploadedFile.ContentLength <= 500 * 1000 * 1024); 

    if (customerFile == null) 
     throw new ArgumentException("Error: Uploaded file must be less than 500MB"); 

    //determine the extension of the file 
    String inputFileExtension = ""; 
    var regexResult = Regex.Match(customerFile.FileName, "^.*\\.(.{3})$"); 
    if (regexResult.Success) 
     inputFileExtension = regexResult.Groups[1].Value; 

    if (inputFileExtension.Length == 0) 
     throw new Exception("Error determining extension of input filename."); 

    //build a temporary location on the disk for this file 
    String outputFilename = "{0}/{1}.{2}".FormatWith(uploadPath, Guid.NewGuid(), inputFileExtension).MapAbsolutePath(); 
    if (File.Exists(outputFilename)) 
     throw new Exception("Unable to create temporary file during upload."); 

    //Get some information from the session 
    String ownerId = "Partner_" + this.GetSession().UserAuthId; 

    //Write the temp file to the disk and begin creating the profile.       
    try 
    { 
     //Move the file to a working directory. 
     using (var outFile = File.OpenWrite(outputFilename)) 
     { 
      customerFile.WriteTo(outFile); 
     } 

    } 
    catch (Exception ex) 
    { 
     throw new Exception("Error creating profile with uploaded file. ", ex); 
    } 
    finally 
    { 
     //Clean up temp file no matter what 
     try { File.Delete(outputFilename); } 
     catch (Exception delException) { } 
    } 

    return new PostUploadResponse 
    { 
     Title = request.Title, 
     Success = true 
    }; 
} 

ファイルのアップロード、および応答が正しくブラウザに渡され、たとえ正しいss-idとsp-pidが要求の一部として送信されたとしても、その後の任意のサービスへの呼び出しはにリダイレクトされます。

ファイルをアップロードするたびにユーザーセッションが終了する原因は何ですか?

多くの感謝!

-Z

+0

あなたはHTTPリクエスト/ファイルのアップロードおよび302を示す後続の要求の両方のレスポンスヘッダを含めることはできますか? – mythz

答えて

4

まあ、私はこの1つを解決:

ここで何が起こっているかは、ユーザーがファイルを/ binに/アップロードの代わりに/アップロードで終わるし、アップロードされたということでした。/binの内容が変更されるたびに、App Domainが再起動され、セッションが無効になりました。

このときのバグが.MapAbsolutePath()の代わりに、.MapServerPath()の私の使用は

関連する問題