【发布时间】:2011-03-03 17:25:54
【问题描述】:
我正在尝试创建一个 httphandler,它将拦截我们网站中的示例 pdf 文件。 httphandler 在我的开发机器甚至我本地发布的网站上都可以正常工作,如果我只是尝试连接到测试 url: https://test.com/admin/_/sample_reports/sample.pdf我将被发送到无效访问页面。
所以当我尝试访问它提供 PDF 文档的 URL 时,将它推送到我们的 IIS6 机器。 context.User.Identity.IsAuthenticated 始终显示为 true。
我正在使用表单身份验证。下面是我用作处理程序的代码。
public void ProcessRequest(HttpContext context)
{
if (context.User.Identity.IsAuthenticated)
{
string SampleURL = context.Request.AppRelativeCurrentExecutionFilePath;
context.Response.Buffer = true;
context.Response.Clear();
using (FileStream fs = new FileStream(HttpContext.Current.Server.MapPath(SampleURL),FileMode.Open))
{
int length = (int)fs.Length;
byte[] buffer;
using (BinaryReader br = new BinaryReader(fs))
{
buffer = br.ReadBytes(length);
}
context.Response.Clear();
context.Response.Buffer = true;
context.Response.ContentType = "application/pdf";
context.Response.BinaryWrite(buffer);
context.Response.End();
}
}
else
{
context.Response.Redirect(
"~/Error/invalid_access.aspx");
}}
在 web.config 我有以下表单身份验证:
<authentication mode="Forms">
<forms name="Sample.Web" loginUrl="~/Security/" defaultUrl="~/default.aspx" protection="All" timeout="60" path="/" requireSSL="false" slidingExpiration="true" enableCrossAppRedirects="false" cookieless="UseDeviceProfile" domain="">
</forms>
</authentication>
<authorization>
<deny users="?"/>
</authorization>
【问题讨论】:
标签: asp.net iis forms-authentication