尝试通过代码将文本文件写入C:\ Drive时访问被拒绝异常

问题描述 投票:0回答:1

我需要编程来专门保存动态创建的文件到客户端系统的C:\ Drive。

我尝试了以下代码

                    context.Response.ContentType = "text/plain";
                    context.Response.AppendHeader("Content-Disposition", "attachment; filename= "TextExport");
                    string path=@"C:\TestFolder";
                    Response.TransmitFile(path);
     try
                    {
                        context.Response.End();

                    }
                    catch (Exception ex)
                    {
                        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "ExMessage", "alert('" + ex.ToString() + "')", true);
                    }
                    finally
                    {
                        this.Dispose();
                    }

调试时我收到异常,说明访问被拒绝。

我该怎么办?我特意想保存到C盘

c# asp.net visual-studio-2012
1个回答
0
投票

如果您使用Visual Studio(管理员执行),请检查您是否处于管理模式,如果您使用IIS检查您的应用程序池是否可以在您的目录中写入(C:\)。

enter image description here

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.