Search code examples
asp.nethttp-status-code-403

403 forbidden caused by response object?


In my server side code I'm creating the following response object:

var response = HttpContext.Current.Response;
                response.Clear();
                response.AddHeader("Content-Type", content.Type);
                response.AddHeader("Content-Length", content.Length.ToString());
                response.AddHeader("Content-Disposition",
                string.Format("attachment; filename={0}; size={1}", Server.UrlEncode(content.FileName), content.Length.ToString()));
                response.Flush();
                response.BinaryWrite(content.Image);
                response.Flush();

Is it possible something in this response object is causing the 403 and if so what? If I just run a blank aspx page I don't get a 403 it is only when it goes through the above code that a 403 occurs.


Solution

  • The issue is unlikely to be a mime type issue (so probably not related to the content type being text/plain), though that's an issue in itself.

    Chances are that permissions are not setup correctly, or that .NET is not registered on the server properly. Try running aspnet_regiis on the server again.