How to organize an ASP.NET project [closed] - asp.net

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this question
I am a PHP developer moving into an ASP.NET environment. I would like to know the best way to organize the different types of files.
Right now in my project I have the following:
3 Master Files
5 User Controls
1 Base page class
Several Web Forms
The web forms are organized into directories based on the sites structure. But do I just leave the rest of these things on the root level?
The base class can go into the app_code folder, but where do masters and user controls go?

I usually make a /MasterPages/ folder for master pages and break content down into things like /Users/ for pages in the "Users" section of the site and /Users/Controls/ for controls for those pages.
So something like this:
../ root
/Admin/
/Admin/Controls/
/JavaScript/ (or a /Includes/)
/MasterPages/
/Users/
/Users/Controls/
etc.

Structure your site like you would if you were using PHP. The directory structure doesn't affect anything* until you get into something like ASP.NET MVP.
* aside from page linking

If you put the master files in any directory. It might be possible to make problem of path. So, If you are putting your web files in any directory then put master files also there. For the user and custom control, Make a directory for them and put them in that directory and go to web.config and make a "Controls" child tag in "Pages" tag like this.
By this thing you no need to put "Register" tag on each page where you are using user controls.

Related

Symfony 4 translation files in directories [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I want to save translation files in directory, for example:
/translations/admin/messages.en.xlf
/translations/admin/validation.en.xlf
/translations/client/messages.en.xlf
/translations/client/validation.en.xlf
And how to use these translations in Controllers and Twig templates ?
Translation Resource/File Names and Locations
Symfony looks for message files (i.e. translations) in the following
default locations:
the translations/ directory (at the root of the project);
the Resources/translations/ directory inside of any bundle.
The locations are listed here with the highest priority first. That
is, you can override the translation messages of a bundle in any of
the top two directories.
The override mechanism works at a key level: only the overridden keys
need to be listed in a higher priority message file. When a key is not
found in a message file, the translator will automatically fall back
to the lower priority message files.
Source: https://symfony.com/doc/4.2/translation.html#translation-resource-file-names-and-locations
And later on the same page / chapter
You can add other directories with the paths option in the
configuration:
config/packages/translation.yaml
framework:
translator:
paths:
- '%kernel.project_dir%/translations/admin'
- '%kernel.project_dir%/translations/client'
You can use those as any other translation files, remembering the overriding mechanism quoted here above
Full reference: https://symfony.com/doc/4.2/translation.html

Confuse about web hosting CPanel [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed last year.
Improve this question
I've read some article about deploying a website to a host. It has something like cPanel and we put all the source code into the public_html folder. And we can access those file using hostname.com/index.html will be pointed to /public_html/index.html file. My question is:
In this case, people can totally access all my source code file inside the public_html directory? It's too dangerous
By the way, some modern web design today is not access page through a file, it's instead by route. For example with Java spring MVC project: if I design a route hostname.com/users will return a page with all user, hostname.com/user/1 will return a json with user no.1. Those are all accessed by url route so how can I deploy that website in cPanel.
Please explain to me if anyone knows. Thank you.
To answer your first question, no. Not technically. Static items such as HTML/CSS/Javascript/Media Files can be accessed if they know the URL (Or you leave the indexing option enabled. Use .htaccess to disable that). PHP files are safe. The only thing people would be able to see is the OUTPUT of those. I would recommend using PHP when creating websites if possible.
You can achieve similar results to your second question be utilizing the .htaccess file and it's rewrite properties. You can also use PHP's POST/GET methods to handle events like you're suggesting.
I hope this helps!
Take a look at the file permissions settings available in cPanel on LAMP:
r = read
w = write
x = execute
You have Owner, Group, & World settings each with read, write, & execute values that can enable fine grained permissions on code, files, & folders on production web servers.

How to reorganize contents like the old school in ASP.NET Core MVC?

I have a web site in ASP.NET Core MVC, and I don't want to put my contents inside another folder. I just want to use the old school of creating this file-system architecture at the root of my project's folder:
Styles
Fonts
Scripts
Images
But I can't make ASP.NET Core MVC serving files from them. For example http://domain.test/styles/default.css returns 404.
I've tried to add StaticFileOptions, but I can't get it to work.
Can you help please?
I tried the given solution, that is, to use UseWebRoot("") with empty string to make it refer to the root of my web project. Yet it still returns 404.
I created a Styles folder inside the \bin\Debug\netcoreapp2.0\ and added a Styles.css there and it served the file.
If you are not adding them on the wwwroot folder then you should do more preparation.
This link will help Working with static files in ASP.NET Core
I think before asking you should search some more. For example
this stackoverflow question will help you:
How to Configure an Alternative Folder to wwwroot in ASP.NET Core?

Designing a RESTful API for managing resources as directories and files [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
I am designing a RESTful API that deals (among others) with managing directories and files.
Due to some tricky business rules (listed below) I have some troubles in finding a good structure of the resources and a good URI design...
There are many directories.
A directory has many files.
The list of files can be accessed only from their parent directory.
A specific file can be accessed "globally" (by its id only)
Files can be created, but the client should not be able to specify the parent folder (as new files are saved in a special directory and can only be moved later etc.)
Here's a possible URI design:
Get all directories:
GET /api/directories
Get properties a directory:
GET /api/directories/{directoryId}
Get files within a directory:
GET /api/directories/{directoryId}/files
Get a file:
GET /api/files/{fileId}
Delete a file:
DELETE /api/files/{fileId}
Create a file:
POST /api/files
Is this an awkward design? If yes, why?
Also, if it were to document this RESTful API, this would be a bit awkward too:
Directories resource
Resource URI:
/api/directories
Possible operations:
GET /api/directories
GET /api/directories/{directoryId}
Links to other resources:
(?) How to write this?
There is a link to the Files resource, but that is accessible only when using the second operation.
Files resource
Resource URI:
(?) ... there are two URIs... one for "get all" ("or get many") and one for the rest of the operations.
Possible operations:
GET /api/directories/{directoryId}/files
GET /api/files/{fileId}
DELETE /api/files/{fileId}
POST /api/files
Links to other resources:
Link to Directory resource - note the singular here (?)
Strictly speaking, there is no Directory resource, but there is a Directories one - should I treat these two (Directory VS Directories) separately? please see the question at the end.
Also, this link is available only in the first two operations... How to be more precise when specifying this?
Also, I've seen that some RESTful API documentations have separate entries for the collection-like resource and the instance / element-like resource (for example, see this).
Is such a granular documentation preferable? I guess one advantage would be that the "Links to other resources" (or "related resources") section of the documentation would be more precise. Or am I wrong?
Any idea is appreciated!
Thank you :)
I wouldn't say that what you have is particularly awkward. If it were me, I would support these URLs:
GET /directories
GET /directories/{directoryId} // includes a link to the files in the directory, such as /files?directoryId={directoryId}
GET /directories/{directoryId}?expand=files // includes a child collection with links to each individual file resource, and possibly other metadata as well
GET /files
GET /files?directoryId={directoryId}
POST /files
GET /files/{fileId}
DELETE /files/{fileId}
The /directories/{directoryId}/files paradigm is common, but not my favorite. If the user wants the files for a directory, they can use a query parameter on /files. If they want the files at the same time as the directory, they can use a query parameter on /directories/{directoryId}.
This is, of course, all subjective. Without knowing all the specifics, nobody's going to be able to give you a canonically correct answer.
As far as the documentation goes, there's no hard-and-fast structure. If you don't like what you have, change it to avoid the awkwardness. Also, you do have several Directory instances. Each resource that gets returned from /directories/{directoryId} is a Directory.

Accessing folder outside the website directory in asp.net

I have around 20 websites created a single web-server, now i have made a tool which will be common for all the websites, so i have a common user-control, which i am using on .aspx file inside all the website
Now i want to keep these user-controls in a location outside the website directory so that i can access these same control to all the websites.However i cannot find a way to get the directory outside the website's root directory. I googled around and saw the option to make the directory as virtual one, so that it will be accessible to the site, but here i would have to link the folder to one website at a time, so it would be same keeping controls in separate websites, which i want to avoid for update reasons.Can anyone tell me how can i achieve this.
Hi In rough unchecked code something like:
You can access like this.
webRootPath = Server.MapPath("~")
docPath = Path.GetFullPath(Path.Combine(rootPath, "..\Documents/MyDocument.xml"))

Resources