c# - System.UnauthorizedAccessException on a simple ASP.Net File.IO operations -


ASP In .NET (hosted) I need a simple file IO operation to read data from a file and then a download. It's really simple.

I am receiving System.UnuthorizedAccessException while executing the following code:

  System.IO.FileStream fs = new System.IO. FileStream (Path, System.IO.FileMode.Open);  

Locally works fine, but when I upload to a shared hosting account, I get the exception exception.

What's strange is that if I enter the full path for the full file in the browser, I can see and use the file.

As everyone has mentioned, this is most likely because the ASP process is up to the file directory. Security permission not found.

If you can use the file through your browser, then you can read the file file instead of using HttpWebRequest.

If you do not have admin control over the server, then it will understand.

Here are some sample codes for using HttpWebRequest:

  /// & lt; Summary & gt; /// presents a request for the specified url and returns a text response, or string. If the request is unsuccessful /// & lt; / Summary & gt; /// & lt; Param name = "uri" & gt; To submit a request to the url & Lt; / Param & gt; /// & lt; Returns & gt; Text response, or string from the specified URL. If the request is unsuccessful. & Lt; / Returns & gt; Protected string getPageResponse (string URL) {// Set default result string response text = string. Empty; // url Create a request to target System.Net.WebRequest request = System.Net.HttpWebRequest.Create (url); // Set the request requests credentials. Credential = System met. Credential cache. Default credentials; // Request response from System.Net.HttpWebResponse response = (System.Net.HttpWebResponse) request.GetResponse (); // Receive the response code (format it as decimal) String status = response. Status code Toaster ("D"); // If we have successfully responded (2XX or 3XX) (position code cordless ("2") || condition code ("3")) {// Receive feedback stream so that we can read it Section responsestream = response Gateresonsstream (); // Response StreamReader responseReader = Create a stream reader to read new StreamReader (responseStream); // Read feedback text (this should be javascript) responseText = responseReader.ReadToEnd (); } // Request return feedback lesson text; }  

Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -