implementing virtual path - path

i want to use virtual path in my web application using asp.net
is there anyone who know how to do this?

Related

Accessing a Virtual Directory from a Web API

I have a folder of files (form templates) that need to be accessed from both a .NET Web API application and a separate .NET MVC application. The folder for these form templates is outside of the websites. Ideally, I'd like to be able to store the path in the Web.Config files so that the applications can be easily tested in a local environment.
I tried setting up virtual directories on the hosted site but couldn't figure out how to reference them in the Web API. I tried several means of referencing the Virtual Directory that did not work. Most posts suggested trying Server.MapPath("MyVirtualDirectory") but that returns "....\wwwroot\MyApiController\Action\MyVirtualDirectory", not the physical path of the virtual directory.
I removed the Virtual Directory and attempted to "navigate" to the correct path but was blocked by "Cannot use a leading .. to exit above the top directory".
So what is the correct way to access a resource using a virtual directory in .NET Web API application? Is the same method going to work for the .NET MVC application?
You need to use HostingEnvironment, like:
public static string MapPath(string path){
string result;
result = HostingEnvironment.MapPath(path);
return result;
}
Additionally HostingEnvironment provides features like ApplicationPhysicalPath:
result = HostingEnvironment.ApplicationPhysicalPath + "App_Data\\somefile.xml";

Where to store public images in an ASP.net MVC Application?

I'm quite new to the MVC Framework.
I have images I want to be able to be accessible with an absolute URL. I was told to create /images under /Content. I try to navigate to http://myapp.net/Content/images/img.jpg, and I get a 404.
Perhaps I don't know what the external URL is to get to that folder? Would there be any settings I need to set - in web.config? In IIS? (Actually, I'm running the app off VS 2013).

How do I serve static files from mvc without using content folder?

I want to be able to have a folder which allows regular access like the \content folder except that it holds a ClickOnce application. I can't seem to be able to achieve this using Mvc, but I'd like to have this folder accessible without Mvc seeing it as a controller action.
I tried using routes.Ignore(theUrl), but this seemed to have no effect.
There are two ways you can do this. The first is where you are currently going, which is to satisfy it with routing. You should be able to use the following to ignore the intended route:
routes.IgnoreRoute("...")
However, this might not be the right approach from a security stand point. I would recommend you define an explicit action to download your click-once exe. Have a look at this q/a as an example of using the FileContentResult class.
The reason for this is that you can control security for that file without having to open up access levels to other directories.
Edit: If this is for an entire directory, you can still follow this same approach.
Set up the folder as a virtual folder in the website on IIS. then you can set the url in the code to point to the machine serving the request and to the virtual folder on the web server.

ASP.Net MVC 2.0 with IIS 6.1 Windows 7 static contents path issue

I am working on ASP.Net MVC 2.0 application with .Net framework 4.0 and IIS 6.1 (Windows 7).
When I created virtual directory for my application, the URL routing working for all server side actions. But it doesn't consider static content path like images, scripts and style.
Please help me ASAP.....
UPDATE:
Hi David Thanks for your timely reply.........
Please note the following sample:
I have created a MVC application with the Controller named as Home, inside the controller I am having a action named myhome when I accessing the routed path like localhost/Home/myhome, its accessed fine. Suppose I have some images on the view page. Those images not shown. Because of invalid path. But the same working with Windows 2008 R2's IIS7.0 and run directly from Visual Studio 2010. Only it didn't work on Virtual directly....!!
Are you hard coding paths with a leading slash? If so, stop and use Url.Content() instead. That will automagically handle your virtual directories.
Not much information to know your exact problem but something you can check is if "Anonymous authentication" is using your application pool identity.
On IIS7 double click on Authentication feature for your site and then "Edit..." (right click on "Anonymous Authentication) and change to "Application Pool identity" instead of IUSER.

Putting a ASP.NET MVC web site in a subfolder

For a shared test environment I need to place an ASP.NET MVC 1.0 web application in a subfolder. So the URL to the web applications start page will look something like http://192.168.100.1/webapp1/.
Is this possible at all or must it always reside in the root?
Er yes- just create a virtual directory. Let us know if you want any further info (I suggest you try Google first though).

Resources