I am creating directories, and writing files to a shared folder within my web application that is being hosted on Windows Server 2008. I am running the application pool with an identity of ApplicationPoolIdentity.
To give you an idea of my setup so far.. I've set permissions to the root of my web application root directory to two different users: "IUSR" and "IIS APPPOOL\MYPOOL". I'm using the name "MYPOOL" as the name of my application pool, so it's easy to reference.
The application is unable to modify and write to a shared folder. I right clicked the shared folder that I'm creating directories in and writing to, and clicked on the "Security" tab. Then I clicked "Edit". Under objects, I checked "Computer". Then under LOCATION, I've tried the machine/server running my web application. I wasn't able to find my "MYPOOL" user however under the users. I tried to follow this link, but it wasn't very complete. I don't know which user to use. I continue to get a System.IO exception because it doesn't have permissions. Once I know which user to use, I will have to give "Modify" permissions to the "ExportPath" directory.
http://grekai.wordpress.com/2011/05/23/permissions-for-shared-folder-for-iis-7-application-pool-identity-across-domain/
For a quick test, I made a dummy page called FilePermissionsTest.aspx, and put some code to write a file to create a directory and write a file in my Page_Load event of the code behind. But I haven't gotten far enough to test it.
...
<div>
Check to see if the file "_File_Permissions_Test.txt" was written to <% Response.Write(Data.ConfigurationHelper.ValueFromConfiguration("ExportPath", Nothing))%>
</div>
...
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim exportPath As String = Data.ConfigurationHelper.ValueFromConfiguration("ExportPath", Nothing)
If exportPath = String.Empty Then Return
Dim exportDirectory As DirectoryInfo = Directory.CreateDirectory(exportPath)
Dim writer As StreamWriter = File.CreateText(Path.Combine(exportDirectory.FullName, "_File_Permissions_Test.txt"))
writer.WriteLine("TESTING... " + DateTime.Now().ToString)
writer.Flush()
writer.Close()
End Sub
as I've written at my post :
GreKai.WordPress.com
You should have entered the computer name and not the ApplicationPoolIdentity. That was your problem.Try it out ! It should work.
The steps are :
Go to the Shared Folder –> right click –> properties -> security –>edit –> add (so far as usual ) -> choose object types –> check on computers –> now enter the computer name where your application is working from , where you published your application.
To solve this one, our server administrator created a domain user in the domain controller called domainuser. Then I went into the IIS 7 application pool advanced settings, and changed the Identity from ApplicationPoolUser to "{domain name}\domainuser" (under the Custom Account field) and entered the password for the account. Then I set write permissions (under the folder properties > security) on that shared folder for {domain name}\domainuser. It worked great.
Related
In case, i'm create function to process excel and in the end of process i want to save excel into my "Download" folder in my pc.. but i get a different folder path between my pc and my server.. when i running my application using my pc, i get path "C:/Users/MyPCUserName/Downloads" but when i running application on published file (iis server), i get path "C:\Users\SYSTEM\Downloads\85FE1000".. I don't know what's the wrong with my code / function..
This my Code :
Private Sub myMethod(ByVal pProjectNo As String, ByVal pOrderNo As String)
Dim dt As DataTable = ClsUploadBreakDownInquiryDB.GetFinalInspectionData(pProjectNo, pOrderNo)
if dt.Rows.Count > 0
'My Function Here
Dim user As String = System.Environment.UserName
exl_b2.SaveAs("C:\Users\" & user & "\Downloads\" & pProjectNo & "_" & Microsoft.VisualBasic.Format (Date.Now, "yyyyMMdd_HHmmss") & ".xlsx", Excel.XlFileFormat.xlOpenXMLWorkbook)
End If
End Sub
You can save a up-loaded file on your web server quite much any place you want.
However, if you talking about a client side user - and their browswer download lcoation? You have ZERO, but 100% ZERO control over that location.
In fact, the user might be using a iPhone, or Android - and not even a desktop comptuer.
You do not have ANY ability in ANY case to control the location of a user download of a file. Files on the local computer are 100% hands off. When they download, it will usually go to their downloads folder - but the user settings control that.
You can't grab, see, or set ANY file location on the client side computer. I mean, if you could do that, then when you come to my site to view a cat picture? My code would then rummage around on your computer - looking for files called passwords, or files called banking etc and steal them
So, server side code behind? Sure, you can in most cases save the file on the web server computer anywhere you like - it don't matter a whole lot.
However, if you talking about client side computer locations for the user and their browser hitting your web site? No, you have zero information, zero control over the users files, and even where they choose to save, or download such files - that is their computer - and browsers give protection for reasons of security.
This can sometimes be confusing when using Visual Studio during development, since your computer, your browser and your web site are all running on the ONE SAME computer, but in a typical deployment, that of course is not the case. So, code behind has zero knowledge about the users local file system.
As a result, you cannot grab, or set ANY kind of file location information on the client side computer.
So, saving to "users" with code behind is ONLY going to apply to the code behind web server "user", and has nothing to do with the client side user.
As a general rule, any and all folders you work with and use from code behind? In EVERY case that should be a sub folder of your root of your project.
Keep in mind:
Any markup code - urls - that is relative to your web site
Any code behind - plane jane windows path name.
So, if you add a folder to your project, it might be say folder UpLoadFiles.
So, then web based, mark up based will be like this:
https://localhost:44392/UpLoadFiles/doc.pdf
So, UpLoadFiles is simple a sub folder in your project.
However, in code behind, your code ALWAYS works with plane jane valid windows file names. So, to convert above to a plane jane file path in windows? You do this:
Dim strFile As String = Server.MapPath("~/UpLoadFiles/abc.txt")
Dim strText As String = File.ReadAllText(strFile)
At this point, now str file is a plane jane valid full good old fashioned windows file name.
So, code behind = always plane jane window path name
So, web markup and URL = always a relative path from your project root.
dim strTextFile = File.ReadAllText(strFile).
There are so many similar questions around the web, but none of them have helped me with this.
I have an asp.net application on a company intranet server. It is used to access a database on another file server, which also contains a number of images relevant to each record in the database.
I am a developer, but not a network person. I know a little bit about IIS, and using the IIS Manager, I created a virtual directory inside the asp.net application folder that maps to the UNC address on the other server where the images are. Using IIS Manager, I can explore the virtual directory and see all the files there. The problem is getting them to show up in my asp.net application.
I've tried setting permissions on the folder for Network Service, IUSR_aspnetserver, and my own credentials; I've tried various permutations of the path string, with / or // or \ or \, etc. I've tried impersonation, but I don't know if I am doing it right. I've placed a "debug" label on the page that tells me the path of the image while the app is running, and it is correct. Nothing seems to work.
Obviously there's something I am missing, but my network comprehension is around zero, my IIS experience is hardly any better, and I can't seem to get our staff of IT "experts" to help. And before you jump to any conclusions, I have a great personality.
Any ideas would be appreciated.
Thanks!
EDIT for #MohsinMehmood:
(I hope this is not too convoluted)
The page has a mapped drive in IIS to UNC share \\OtherServer\AppName\Images to a folder named ReceiptImages.
The web.config file has this entry:
<appSettings>
<add key="ImageFilePath" value="ReceiptImages/"/>
</appSettings>
And in the PageLoad event I have
ViewState("ImagesPath") = ConfigurationManager.AppSettings("ImageFilePath")
To create a global path string.
Then in code (VB) it's:
Dim btnReceiptThumbnailButton As New ImageButton
With btnReceiptThumbnailButton
.ID = "btn" & LineItem
.CssClass = "thumbnails"
.ImageAlign = ImageAlign.AbsMiddle
.Visible = True
.BackColor = Drawing.Color.White
.BorderColor = Drawing.Color.Black
.BorderWidth = 1
.ImageUrl = ViewState("ImagesPath") & LineItem
.CommandName = "GetReceiptImage"
.CommandArgument = LineItem
End With
I don't know if it was important enough to mention that the image is being placed in a button control to make it a thumbnail.
Web Forms project / VB / ASP 4.5.2 / VS2015
EntityFramework 6.1.3 / Identity.EntityFramework 2.2.1
Other packages in NuGet all show current versions
I have a webapp using the VS template which includes pages that create users etc. I have created users and they can/can not access folders according to the web.config in the various folders.
Now I need to add roles and attach roles to users.
I can create roles using
Dim createRole As String = RoleTextBox.Text
Dim RoleManager = New RoleManager(Of IdentityRole)(New RoleStore(Of IdentityRole)(New ApplicationDbContext()))
Try
If RoleManager.RoleExists(createRole) Then
Msg.Text = "Role '" & Server.HtmlEncode(createRole) & "' already exists. Please specify a different role name."
Return
End If
RoleManager.Create(New IdentityRole(createRole))
etc
Next I need to attach roles to users, for which I have got:
Public Class admin_superadmin
Inherits System.Web.UI.Page
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim UserManager = New UserManager(Of IdentityUser)(New UserStore(Of IdentityUser)(New IdentityDbContext()))
UserManager.AddToRole(DropDownList5.SelectedValue, DropDownList6.SelectedValue)
Label1.Text = DropDownList5.SelectedItem.Text + " Was added to the " + DropDownList6.SelectedValue + " Role."
End Sub
However when run this fails at the line usermanager.addtorole with the message:
System.InvalidOperationException: UserId not found.
The DB tables were created by the app. In table AspNetUserRoles are fields UserID, RoleID.
Much appreciated if someone could help identify the problem.
Coming to this as a front-end designer wanting to authenticate users but having never used Identity or MVC, in the end I figured it out and these would have been a ten minute way to get a simple web app up and running with authentication and roles, using a remote db:
File > New Project > Web > ASP.NET web application > Web forms
In web.config, change the DefaultConnection to point to my existing remote MSSQL db
In the solution explorer Account > Register.aspx > View in Browser
in the browser, register a new User: in the remote database, all needed authentication tables are set up for me and I can now add and modify users from the VS template project pages in the Account folder. But I cannot use Roles yet.
Project > Add New Item > VB (for me) > Data > ADO.NET Entity Data model > EF Designer from database > make it refer to DefaultConnection > tick all tables
I can now create an admin folder and in it a page with a few controls and the code
UserManager.AddToRole(user.Id, ) will succeed and not give the error reported in my original question.
Hope these steps might help another beginner.
I have a requirement to create a directory on my applications server which is secure to all, but the application itself.
I have read this article
System.IO.Directory.CreateDirectory with permissions for only this current user?
Converting to VB, the code it suggests is:
Dim ds As New DirectorySecurity()
Dim sid As New SecurityIdentifier(WellKnownSidType.CreatorOwnerSid, Nothing)
Dim ace As New FileSystemAccessRule(sid,
FileSystemRights.FullControl,
AccessControlType.Allow)
ds.AddAccessRule(ace)
Directory.CreateDirectory(Dir, ds)
But when I follow that code instruction there, I cannot add files to the directory I have created.
I am guessing I should change the value of WellKnownSidType but I do not know what to!
To recap - what I need is a directory which my application can read and write to, but a user cannot access from a web browser to download any content.
Any help much appreciated!
Forgive me if this is a dumb question, I'm new to ASP. I have a virtual Windows Server 2012 handling ASP pages, passing them to the host for testing purposes. There is a global.asa file which declares several Application-level variables, though it doesn't seem to be working. I'm not sure if I need to call the file or what, though I can't find any reference to calling it on the internet.
In global.asa:
<SCRIPT LANGUAGE=VBScript RUNAT=Server>
Sub Application_OnStart
Application("someVar") = "testing..."
'More vars...
End Sub
</SCRIPT>
In default.asp: (Or any other file for that matter)
Repsonse.Write(Application("someVar"))
Nothing will output.
However, if I specify a value immediately beforehand like so:
Application("someVar") = "testing..."
Repsonse.Write(Application("someVar"))
It will output "testing..." like it should.
After that, removing the Application("someVar") = "testing..." line will still output "testing...". So the variable is being retained, it just isn't being set initially by the global.asa file.
Is there something else I need to do to initialize them via the global.asa file? Is it a problem with my virtual server setup? I should probably mention that navigating to the global.asa file via the web browser gives me a 404 error. I'm not sure if the server is trying to hide it, but I am as certain as I can be that it is in the same directory as default.asp, the browser just refuses to verify this.
Global iis defined application variables will not work if the site isn't set as a application.
You need to open IIS, and setup the website as new site.
open iis manager
expand servername,
expand 'Sites'
Any sites you have will be listed.
to setup new site
r-click on 'sites' and select 'Add Web Site'
Give it a name, select its location by browsing, and if needed set the host header eg www.mytestdomain.co.uk
OR (this is often the cause in test setups)
If you have a default site setup and this application is a subfolder then you can set that subfolder as an application by simply right clicking on folder and choose 'Convert to application'. click ok on the popup to confirm.
<SCRIPT LANGUAGE=VBScript RUNAT=Server>
Sub Application_OnStart
Application("someVar") = "testing..."
'More vars...
End Sub
</SCRIPT>
May be, you set the var someVar in Global.asa after the application is already running! And if so, Application_OnStart event is already executed!!!