Why my httpwebrequest post to myhandler.ashx is rejected with status code 401

南笙酒味 提交于 2019-12-08 11:14:36

Have you tried turning off Integrated Windows Auth and just leaving anonymous checked? Does it make a difference?

Your answer: "I think it made things worse because now I cannot even browse to default.aspx. I get this: HTTP 401.3 - Access denied by ACL on resource Internet Information Services"

My response: This is actually a good thing. This means we're getting closer to what is going on. If you're getting that error message and the only thing you have enabled is anonymous authentication via IIS, that means that the ASP.NET impersonation user doesn't have NTFS permissions on the files in question.

I'm not sure if you are on XP or Win 2k3, but now you want to check and make sure that either the ASPNET (XP) or Network Service (Win 2k3) users have at least read access on the files in question. Make sure that user has at least that level of access and then let me know how it goes.

Update: I don't know why I didn't think of this before. You may need to set credentials on your HttpWebRequest. To use the credentials of the current user, try adding this to your request.

HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(URI);
myRequest.Credentials = CredentialCache.DefaultCredentials;

If you need to add different credentials you can try Network Credentials

There's a good explanation of credentials here.

Hope this helps.

Looking at your ProcessRequest(), you do the following:

string returnURL = context.Request.ServerVariables["HTTP_REFERER"];

Based on how you are calling it with HttpWebRequest, this variable will be null. Then when you create your msgReturn, it will look something like this:

?n=XXX%m=YYY

When you redirect to this URL, it will probably not be found which is what is returning the 401.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!