473,394 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Access is denied

This is my code.

When i execute this code, it throws "Access to the path "somepath" is denied."

Expand|Select|Wrap|Line Numbers
  1. FileStream file = new FileStream(filePath, FileMode.Create, FileAccess.Write);
  2.                 StreamWriter sw = new StreamWriter(file);
  3.                 try
  4.                 {
  5.                     sw.Write(vendorInfoStr.ToString());
  6.                 }
What is going wrong.

Thanks,
Srinivasan R.
Jan 22 '09 #1
14 16408
PRR
750 Expert 512MB
@srinivasanr
What application are you using? if its asp.net then it doesnot have fileIO permission...or if you maynot have permission to create in that folder...
Jan 22 '09 #2
PRR
750 Expert 512MB
Expand|Select|Wrap|Line Numbers
  1. using System.Security.Permissions;
  2.  
  3. string filePath = @"C:\Zp\Er.txt";
  4.  System.IO.FileInfo fname = new System.IO.FileInfo(filePath);
  5.  
  6.               FileIOPermission permis = new FileIOPermission(FileIOPermissionAccess.AllAccess, fname.DirectoryName);
  7.  
  8.               bool all = true;
  9.               try
  10.               {
  11.                   permis.Demand();    
  12.                   permis.PermitOnly();             
  13.  
  14.               }
  15.  
  16.               catch (System.Security.SecurityException ex)
  17.               {
  18.                   all = false;
  19.               }
  20.  
  21.               if (all)
  22.               {
  23. //do your stuff
  24. }
  25.  
Jan 22 '09 #3
I am using only ASP.NET. But this code is working in my testing environment.
But it is not working in my production server.

This is the log file.

Expand|Select|Wrap|Line Numbers
  1. 17:00:03 [9] ERROR VendorIntegration - Error while Transformming Vendor: 
  2.  
  3. System.UnauthorizedAccessException: Access to the path 'some path' is denied.
  4.  
  5.    at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
  6.  
  7.    at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
  8.  
  9.    at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
  10.  
  11.    at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access)
  12.  
  13.    at DataAccess.Process.VendorIntegration.TransformSource(IList vendorInfoList) 
Jan 22 '09 #4
PRR
750 Expert 512MB
You could either use impersonation How to implement impersonation in an ASP.NET application
or give rights to asp.net on that particular...
Jan 22 '09 #5
thnaks for the reply.

I have used the methods Impersonate the IIS authenticated account or user and it is working fine when i call the code through UI.

But i have called that code automatically by using Thread concept.
Now it throws the same error "UnAuthorizedAccess" exception. Access is denied.

What can i do for it?
Jan 23 '09 #6
semomaniz
210 Expert 100+
You will have to give write permission to the folder that you are outputting the text file through the IIS.
Jan 27 '09 #7
@semomaniz
I do not know how to give write permission to the destination folder through IIS. Please direct me.
Jan 28 '09 #8
PRR
750 Expert 512MB
@srinivasanr
I am not sure whether this is the right way.. normally for testing i usually do this ... do ask a system admin for the "correct" way.
1. go to properties of the folder you want to give asp.net write rights.
2. Click security->add->advanced ->click on find now...Here you will find list of users... depending on what you have installed on your computer... click asp.net account and add and give permission to it ...
Jan 28 '09 #9
I gave all permissions to all users and it is working when i call that code through UI. But it is not working when i call that same code through automated job by the use of Thread concept.
Jan 28 '09 #10
PRR
750 Expert 512MB
@srinivasanr
What do you mean by that?
Jan 28 '09 #11
I mean i call the same code through Thread concept at a specified time.
Jan 28 '09 #12
PRR
750 Expert 512MB
@srinivasanr
Within the same application using a thread... shouldn't be a problem... Could you post some code and error message?
Jan 28 '09 #13
Please see my first post...
Jan 28 '09 #14
This is my code

Expand|Select|Wrap|Line Numbers
  1. FileStream file = new FileStream(filePath, FileMode.Create, FileAccess.Write); 
  2.                 StreamWriter sw = new StreamWriter(file); 
  3.                 try 
  4.                 { 
  5.                     sw.Write(vendorInfoStr.ToString()); 
  6.  
  7.                 } 
This is my log message

Expand|Select|Wrap|Line Numbers
  1. 17:00:03 [9] ERROR VendorIntegration - Error while Transformming Vendor:  
  2.  
  3. System.UnauthorizedAccessException: Access to the path 'some path' is denied. 
  4.  
  5.    at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) 
  6.  
  7.    at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) 
  8.  
  9.    at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy) 
  10.  
  11.    at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access) 
  12.  
  13.    at DataAccess.Process.VendorIntegration.TransformSource(IList vendorInfoList)  
Jan 28 '09 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: calfdog | last post by:
Hello, Does anyone know a workaround for calling fireEvent. With the latest from Microsoft OS XP2 and Hot fixes to IE it now gives an "access denied" error in Python when called. Here is what...
0
by: Steve | last post by:
Hi, Yesterday I signed up for another dedicated linux server with the hosting company I use and I am having problems getting MySQL 4.1.3 working on it. I've tried just about everything I can...
3
by: Ian | last post by:
The beginning of my assembly that I am getting the access error from looks like this. ********************************* Imports System.EnterpriseServices Imports System Imports...
4
by: Fabian von Romberg | last post by:
Hi, I have installed Sql Reporting Services on 2 machines, one is WIN 2000 PRO and the other one is WIN 2000 ADV. SERVER. When I try to access a report using the webbrowser, I get the following...
9
by: | last post by:
Hi All, I have allready tried to ask a similar question , but got no answer until now. In the meantime, I found, that I cannot understand some thread-settings for the Main() function . If I use...
6
by: ASP.Confused | last post by:
I have an ASP.NET page writtein in VB that uses ADODB. I just had to force-install MDAC 2.8 after I tried to rollback to 2.6 (my web host uses this, and I wanted to be compatible with them.) I...
0
by: ASP.Confused | last post by:
The old message looked a little stale, so I am re-posting it here. Anybody have any ideas of what I could do?!? The previous responses to this question are below. If you want to look at the...
12
by: Ron Weldy | last post by:
I have a test server runinng 2003/IIS 6 with a mixture of asp and asp.net files. On my workstation I have a share set up to the folder where the web files reside. I am just doing quick and dirty...
3
by: Shailesh Humbad | last post by:
I figured out what was causing the "Access is Denied" error when calling functions from referenced DLLs in my service. I've tried to be very detailed, so bear with me. It turns out that...
8
by: Jeremy Ames | last post by:
I am trying to move an application from my system to a new test system. I really should have tried an easier program first, but I didn't really have a chance. My application was originally written in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.