ColdFusionページからPOSTされたHTTPHandlerはすでに作成されていますが、正常に動作します。 ASP.NETでWebアプリケーションを作成しようとしています。.aspxページから.ashxハンドラにフォームを送信できます。myhandler.ashxへの私のhttpwebrequest投稿がステータスコード401で拒否された理由
アプリケーションのトレース(trace.axd)私の最後の3つのエントリとして次を示しています。
2 8/14/2009 1:53:56 PM /Default.aspx 200 GET View Details
3 8/14/2009 1:54:04 PM /Default.aspx 200 POST View Details
4 8/14/2009 1:54:13 PM /UploadHandler.ashx 401 POST View Details
私は.ashxファイルにブレークポイントを持っていますが、それが原因で401のステータスコードの私は推測する(到達されることはありません)。ここでは、ハンドラに投稿しようとしているのdefault.aspxからのコードの抜粋は以下のとおりです。ここで
protected void UploadHandlerButton_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
try
{
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] data = encoding.GetBytes(BuildFormData());
string baseAddress = "http://" + Environment.MachineName;
string pathInfo = Page.ResolveUrl("UploadHandler.ashx");
string URI = baseAddress + pathInfo;
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(URI);
myRequest.Method = "POST";
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.ContentLength = data.Length;
Stream newStream = myRequest.GetRequestStream();
newStream.Write(data, 0, data.Length);
newStream.Close();
}
catch (Exception someError)
{
LogText("FAILURE: " + someError.Message);
}
}
}
はUploadHandler.ashxファイルからのコードの抜粋である(しかし、これはあるようには見えません到達):
public void ProcessRequest(HttpContext context)
{
string returnURL = context.Request.ServerVariables["HTTP_REFERER"];
string message;
message = UploadFile(context);
StringBuilder msgReturn = new StringBuilder(returnURL);
msgReturn.Append("?n=");
msgReturn.Append(HttpUtility.UrlEncode(TRIMrecNumAssigned));
msgReturn.Append("&m=");
msgReturn.Append(HttpUtility.UrlEncode(message));
context.Response.Redirect(msgReturn.ToString());
}
のdefault.aspxとUploadHandler.ashxの両方が私のローカルホスト上の仮想ディレクトリのルートにあります。ディレクトリセキュリティが現在「匿名アクセス」に設定されています。「CHECKED」と「Windows統合認証」がチェックされています。
trace.axdディスプレイの[詳細を表示]リンクをクリックすると、私が見たいと思うFormsコレクションのすべてのデータが表示されますが、この401はすべてを停止しているようです。便利な場合はBuildFormData()という小さな関数用のコードを投稿することができます。
EDIT:改訂ハンドラ(影響を与えなかった。同じエラーが発生します)、次のように:
あなたのprocessRequest(見れpublic void ProcessRequest(HttpContext context)
{
//-----------------------------------------------------------------------------------------
// the remainder of this block is alternative to the .Redirect and is useful for debugging.
context.Response.ContentType = "text/html";
//context.Response.Write(TRIMrecNumAssigned);
//context.Response.Write("<p>");
//context.Response.Write(msgReturn);
context.Response.Write("<H1>Trim - Kerberos Prototype for ColdFusion consuming pages</h1>");
HttpContext.Current.Trace.IsEnabled = true;
HttpContext.Current.Trace.Write(null);
HttpContext.Current.Trace.Write("-------");
HttpContext.Current.Trace.Write(context.Request.Form["txtTrimRecordType"]);
HttpContext.Current.Trace.Write(GetUserInfo());
HttpContext.Current.Trace.Write("-------");
HttpContext.Current.Trace.Write(null);
using (Html32TextWriter htw = new Html32TextWriter(context.Response.Output))
{
typeof(TraceContext)
.GetMethod("Render", BindingFlags.NonPublic | BindingFlags.Instance)
.Invoke(HttpContext.Current.Trace, new object[] { htw });
}
}
ありがとうございました。あなたのポイントは有効だと思われますが、なぜ私があなたが見せているラインで止まらないのかについてもっとコメントすることができます。つまり、なぜ401が発生し、どうやって解決できるのでしょうか。私は後でポストに戻ることについて心配します。 –
context.Response.Redirect(msgReturn.ToString());を削除するとどうなりますか? – Keltex
.ashxファイル内の私の修正されたProcessRequest()を表示しているところの私のEDITを見てください..... trace.axdは同じ401エラーが発生していることを示しています。 –