What is the difference between "~/" and "../"? [closed] - c#

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
In code I often find ~/ or ../ with paths but unfortunately it is not clear to me what these are and what the difference is. Which one to use with multiple level directories ?
I guess ../ means domain of site or application?
Can you please guide what they are, and how they are different?

~/ is often refereed to in helper functions such as <%= ResolveUrl() %> for example. It refers to the root of the website whereas ../ simply refers to the parent directory. Both are relative urls.
Let's take an example. Suppose that your website is hosted in a virtual directory called MyApplication. When you use <%= ResolveUrl("~/foo/bar") %> it would generate /MyApplication/foo/bar as output url and this no matter in which WebForm location.

There're two kinds of paths:
Regular paths
Virtual paths
When you just use / or ../ you're using regular paths relative to the IIS - the web server - Web site URL. That is, /myfile.txt would be wrong if your application is hosted in a virtual directory called mydir. In this case, /myfile.txt will end in an URL like this: http://www.mydomain.com/myfile.txt, while you expected http://www.mydomain.com/mydir/myfile.txt.
For that reason, ASP.NET gives you the chance to provide virtual paths. All of them start with ~ character. The ~ character specifies that the resolved URI is relative to the IIS application. Taking the above example of expecting http://www.mydomain.com/mydir/myfile.txt, the right virtual path would be ~/myfile.txt.
Note that virtual paths aren't allowed in non-server controls. This kind of path is used in a selected number of ASP.NET class methods and server controls.

The tilde (~) refers to the application root directory. In ASP, the tilde is used for HyperLinks or Page.ResolveURL.
Two dots (..) refers to the folder that is one level higher than the current folder.

Related

How to render partialView from another application? [duplicate]

This question already has answers here:
MVC Rendering (RenderPartial, RenderAction) Html from another MVC Application
(2 answers)
Closed 5 years ago.
I have 2 applications published in the same site in iis, so the only diference between both is the virtual path, ex: localhost:2020/app1 and localhost:2020/app2. My problem is that in the app1, I want to call a partialView from the app2 and I can't add the references from the app2 to the app1. Any idea how to do that?
The only reasonable way (to me at least) to do this is to move shared partial views to separate library and use RazorGenerator tool to generate code for them. Then when you will reference the library in web projects of both applications those views will be available to use.

Programmatically identify PHP and ASP include dependencies [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 6 years ago.
Improve this question
I am trying to automate the cleanup of legacy/heritage code and I can identify current resources in use from IIS logs but server side pages like .ASP and .PHP have include chains which I would like to be able to identify via code (C#)
In order to narrow the question down as it was too broad ...
OS - Windows 10
Web Server - IIS
Preferred language - C#
Example - any IIS served website
I have code that reads IIS log files where I have identified all static served resources including the initial .ASP or .PHP pages.
I required some accompanying C# code to also detail any .ASP or .PHP included files that were processed on the server and therefore do not appear in the IIS logs.
As it happens I have found the solution and provided an answer below.
I hope this is enough detail to take this off 'On Hold'
Many thanks to #Progrock for pointing me to checking last accessed time for files in target folder. This is what I had to do.
Ensure capturing last accessed time is being set by Windows (see Directory.GetFiles keeping the last access time)
Process.Start("fsutil", "behavior set disablelastaccess 0").WaitForExit();
Also need to restart IIS to stop any cached in memory files
Process.Start("IISRESET").WaitForExit();
A refresh on FileInfo needs to be performed to ensure you get the correct last accessed time (see How can System.IO.FileSystemInfo.Refresh be used).
This resulted in the following code ...
var start = DateTime.UtcNow;
Process.Start("fsutil", "behavior set disablelastaccess 0").WaitForExit();
Process.Start("IISRESET").WaitForExit();
//do work that will access folder. i.e. access IIS web pages
var files = Directory.GetFiles(iisPath, "*.*", SearchOption.AllDirectories).ToList();
files = files.Where(x =>
{
var fileInfo = new FileInfo(x);
fileInfo.Refresh();
return fileInfo.LastAccessTimeUtc >= start;
}).ToList();
I can use this list of files to identify all .ASP and .PHP and any other files that were accessed via the IIS server on page requests.

How to give path properly in C# [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have a folder in my project named Export, I save files to that folder using this code :
document.Save(#"D:\workspace\folder1\Solution.Application.DataExporter\Export\mydocument.pdf");
But when others use this code, they complain that they don't have that path. How can I give path to my code so that it works everywhere? Thanks.
Option 1: Use the Environment.SpecialFolder to get the physical location of a special folder. See here for an overview of possible special folders.
For example, if you want to put the document in 'my documents' folder, then Environment.SpecialFolder.MyDocuments would give you the location to the my documents folder on the current machine.
Code:
var path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
This way you are sure you always have the correct and existing location. If needed, you can always first create an export folder into this special folder with Directory.CreateDirectory(), if it does not exist yet.
Option 2: Of course, you can always ask for a location to the user if you don't want to use a predefined one, by using the SaveFileDialog class, for example.
Create the folder 'Export' in MyDocuments, and then save the file to that directory. As many others have pointed out. You need to save to a directory, that the executing user has access rights to.
string documentFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), #"Export");
if (!Directory.Exists(documentFolder))
{
Directory.CreateDirectory(documentFolder);
}
document.Save(Path.Combine(documentFolder, "mydocument.pdf"));

How to get remote folder names, select them and delete them in C#? [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 6 years ago.
Improve this question
I am brand-new in C# and I wanna do that in C#.
Can you show me the way :)
Enter a remote machine hostname
get list folder names in C directory from the remote machine
select folder names from the list
delete the selected folders
show a message about the process (deleted or not)
Is that too hard? Thank you for your help in advance and sory for my bad English :(
Remote and local file system access in C# (.NET) works the same way. Try for example the following.
var directory = new System.IO.DirectoryInfo("\\server\path\remote\C");
var files = directory.GetFiles();
foreach(var f in files) f.Delete();
For remote drives, for example drive C, the path will be like: \server\c$\folderUnderC (note the dollar sign).
A broad question, here are a few general answers.
Enter a remote machine hostname
Set up a GUI for that (WinForms or whatever you like)
get list folder names in C directory from the remote machine
Look into remote directory services, especially Samba / SMB setup and access for Windows. This question will be usefull.
select folder names from the list
With the appriopiate GUI elements (a TreeView maybe), easily possible.
delete the selected folders
Issue a File.Delete() command for the appropiate path, see link above.
show a message about the process (deleted or not)
Wrap above command in a try-catch, then call MessageBox.Show() or whatever GUI elements you want for that.

URLs like on a visualstudio.com - advanced routing? [duplicate]

This question already has answers here:
Is it possible to make an ASP.NET MVC route based on a subdomain?
(10 answers)
Closed 8 years ago.
I'm writing here becouse one question doesn't let me sleep calmly. How it's possible that site www.visualstudio.com when I sign in to free TFS account, create special 'part' of site with url {myprojectname}.visualstudio.com?. Is it achieveable in my project using ASP.NET MVC 4 or 5? How it doesn't affect in current DNS system? or it affect? What should I read to let my site be so deeply customizable?
for example:
user1.mysite.xx
user2.mysite.xx/aaa/4/sda/something_other
The easiest way is to define a wildcard DNS A or CNAME entry like (BIND syntax):
*.myside.xx. IN A x.x.x.x
In Windows you can use the command line dns tool for it: http://support.microsoft.com/default.aspx?scid=kb;en-us;840687
After that regardless what you write as username.myside.xx it will hit your webserver. From your code you can decide what to do, make a redirect to username.myside.com/username or whatever else

Categories