ASP.NET Access Database Error? - asp.net

I have written some code that uses an Access DB, on my localhost the following - Select, Insert, and Delete queries work just fine and do what I programmed them to do. When I move the application to the staging server, the application throws errors when Inserting and deleting, however the select statements work just fine. I have made sure all permissions are read/write as far as I can tell, does anyone know what I am missing. See the error below.
~~~~~
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.
Exception Details: System.Data.OleDb.OleDbException: Could not delete from
specified tables.
Source Error:
Line 714: OleDbDataReader objReader;
Line 715: objConn.Open();
Line 716: objReader = objCmd.ExecuteReader();

Hmmm ... that's odd. Do you have Modify (Change) file system permissions on the staging server's folder? Hitting the .mdb would create that temp Access file, so if you can select you should have Write on that folder. Check that you have Modify.

Is your MDB file readonly? I am talking about the file-system attribute of the MDB file.

Seems like whatever account is utilizing the .mdb file does not have the necessary rights to the file/folder.
I've found that using an .mdb file for a website just has too many problems. You want to switch to at least SQL Express. You website will appreciate it.

ASP.NET runs under the special ASPNET or Network Service account. Mostly IIS_USERS (located in the machine)
Right click on folder containing the file to be modified by ASP user
Folder->Properties->Security->Edit->Add IIS_IUSRS (of local machine) with upto modify permission.

Related

Not able to download file name containing 'aspx' character in asp .net

Am developing asp .Net web application.
In one of my aspx file am using file to download using generic handler. Everything works great. But when am testing i felt a strange problem. That, if am uploading a image or document with file name containing aspx character for Eg; aspxphoto as file name.
Uploading doesnt have any any problem but when i try to download it is throwing error in Generic handler file as
Object reference not set to an instance of an object.
Can anyone help me why this problem happends and how can i fix it?
You will not be able to do this. The IIS handler wants to "handle" the ASPX. You should simply not allow it, or if you have to, rename it to .aspx.uploaded or something. If you allowed, it you could open yourself to hacking.
As another option, you may be able to create a virtual that implements ("no processing") - possibly using the HTTP Handler under the virtual and just disabling script / execute permissions (under handler >> Edit Feature Permission >> Script OR under Virtual >> Edit permissions >> Special >> Turn Execute off.
I would not recommend the last, since it will add complexity when migrating between test and live AND for recovery (DR).

ASP - Permission denied

before I start, I'm a PHP programmer, not an ASP programmer, but at my job, they use ASP and I don't have acces to the server, but I can contact the person in charge.
I'm working on an ASP function for work and I alway hit this "Permission denied" error. I made some search and I found that the account need permission to run the script. It's maybe just me, but I don't understand that ASP check the user before run a script, I mean, it's a public website, obviously they will not have acces if I don't.
Can I change the file so anyone can run it ?
EDIT :
My script is trying to edit a file on the server
dim fs,f
set fs=Server.CreateObject("Scripting.FileSystemObject")
set f=fs.OpenTextFile(Server.MapPath("test.txt"),8,true)
f.WriteLine("This text will be added to the end of file")
f.Close
set f=Nothing
set fs=Nothing
Thanks
The account that IIS uses (probably iusr) needs to have read/write permissions on the target folder. I would recommend using a temp folder (anything other than the website's root folder)
By default, the account will have no permissions. That's simply basic security. You need to have whoever administers that machine give permissions on an appropriate location.

Some or all identity references could not be translated while trying to create directory via asp.net mvc web application

I should be able to create a default directory inside project's root directory when the application_start method(inside global.asax)is called for my asp.net web application.
As IIS users dont have full rights to webroot directory(for directory create) i get access denied error message while trying to create the directory.Also IIS users wont be given full access to the root as per client.I am planning to implement like below to meet the expectations of client.Please let me know if there is any better way out for than this approach?
Approach 1:
a.Create a new user account(windows) in the server.
b.Keep the user account name in config file.
c.Read that account from the config file and create directory with that user account using Directory Security object.
Code:
DirectorySecurity dacl = new DirectorySecurity();
string useraccountForDirectoryCreate = System.Net.Dns.GetHostName() + "\\" + "testaccount";
dacl.AddAccessRule(new FileSystemAccessRule(useraccountForDirectoryCreate,
FileSystemRights.FullControl,
InheritanceFlags.
ContainerInherit |
InheritanceFlags.ObjectInherit,
PropagationFlags.None,
AccessControlType.Allow));
Directory.CreateDirectory(imageDirectory, dacl);
The above thing worked locally in IIS server(Haven't tested on client's IIS server)
My concern with this:I think it wont be a feasible to ask the client to create a user account to be
created in the server for just creating the single directory.Also in future he might require to give access to more user for directory create.It wont be feasible to
keep on creating the windows account.
Apporach 2:
a)Create a IIS user account having full access to web root for directory create.(is this a better way out,it is same as giving the IIS user full access to web root isn't it.?Please clarify.)
b)Keep the account info in web config file.
c)Read the account info from web config file and create the directory with permisson with the above piece of code.
Problem with this approach:Is i get the following error.
Some or all identity references could not be translated
when the following statement is invoked.
dacl.AddAccessRule(new FileSystemAccessRule(useraccountForDirectoryCreate,
FileSystemRights.FullControl,
InheritanceFlags.
ContainerInherit |
InheritanceFlags.ObjectInherit,
PropagationFlags.None,
AccessControlType.Allow));
It looks like i am not able to add the access rule for this newly created user.Why is it so?
I have googled enough for the above error message and tried to understand but i am not able to resolve the error.I am not able to understand the error message at all.Please help with the solution for this problem.Its high time to deliver.

Access to the path 'c:\windows\system32\inetsrv\19.xml' is denied

I have a grid view on page. When i click on a select button of grid view. I am getting an exception like this
Error Message: Access to the path 'c:\windows\system32\inetsrv\19.xml' is denied.
here 19 is the id of the record in the grid view.
Actually it was working fine till yesterday. but suddenly raised the exception.
Every thing here is done by a web service.Web service works fine on all pages but only on one page.The exception is raises only on production system not on development system
It is occurring on only one page. How to resolve this.
Check your create/write/reading rights on the folder the xml is in.
Your application pool identity probably does not have the appropriate rights to create/modify/open the file, causing this error to occur.
Please check the security settings and see if that fixes the error.
You need to use Server.MapPath if xml documents are located under the root of web-app.
string value="19.xml";
string file=Server.MapPath("~/folder/" + value);
...
Try to move your XML data to a DataTable.. hence remove neediness to access directly your file. When everything is done simply save back your changes into the respective xml file.

iis7 / asp.net not showing modification of a file

I have currently moved my asp.net 4.0 web application onto IIS7 (windows 2008 server). I used a test folder to hold files from a directory on the localhost machine, however; when I moved the aspx file over and changed the code(on the server), the application keeps throwing this error
Could not find a part of the path 'C:\Users\***\Desktop\TestFolder\'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Users\****\Desktop\TestFolder\'.
I only have two functions that deal with directories and neither function points to that test directory anymore.
private int checkForFileNumbers()
{
string url = "c:/***/realfolder";
DirectoryInfo directory = new DirectoryInfo(url);
return directory.GetFiles().Length;
}
private void checkForFiles()
{
string url = "c:/***/realfolder";
DirectoryInfo dir = new DirectoryInfo(url);
foreach (FileInfo files in dir.GetFiles())
{
FileDropDownList.Items.Add(files.Name);
}
}
I have tried commenting everything in this aspx file out, only to find that this problem still occurs. I performed the issrestart from the cmd line and nothing changed. Any help would be appreciated.
This is a deployment problem. Your error message is clearly out of sync with your current code. The actual code that is being run from IIS must be coming from an out-of-date binary. As a starting point, I would delete all DLLs in your bin directory on the server and redeploy fresh DLLs. The may also require you to refresh your aspx files depending on what kind of project type you're using.
Once you get this sorted out, I would take another look at how you are deploying updates to your site. Visual Studio and IIS 7 offer some neat deployment options if you want to go that way. Also, you could deploy via Git or SVN. But deployment by manual replacing single files is going to lead you to the type of trouble you are currently experiencing.
If realFolder directory exists under root of your web-app or itself is root then use Server.MapPath method to get real path of virtual folder.
For instance,
String rootPath=Server.MapPath("~"); // It will return real path of current web-app's root.
//OR - In case if want use Server property from separate code file.
String rootPath=HttpContext.Current.Server.MapPath("~/testFolder");
Since you're not referencing the path in your code, it's probably either in one of your config files, HttpModules, Global.asax, or perhaps a DLL.
What other components are you using?
Before moving it to a server, have you tried running the site under IIS on your local machine? Maybe attach a debugger and see where the error is thrown?
Oh, FWIW, the IIS AppPool identity will need to have read permission for your C:/***/whatever folder.

Resources