0

I am a newbie to ASP.net and just can't find any documentation on how to serve static files on ASP.NET. I'm referring to files such as images/javascripts/jars/xls, etc...

To be a little clearer, I am not interested in serving files to the user, but rather to my javascripts, java applets, etc... So what I am looking for is a way to have handle specific GET requests with argument are return the files with appropriate MIME type.

Do you have any suggestions on the different ways to do this ? Thanks a lot !

3 Answers 3

2

Use absolute or root-relative paths to avoid confusion in multi-level pages

in ASP.NET you can use a leading ~ to generate urls relative to the root of current site for most server-side controls, as in: <img src="~/image.jpg" runat="server">

You can also use the ResolveUrl method (and other similar methods) to expand such paths without using server-side controls.

If you need to use those paths within your JS code you can do the below:

var JQueryPath=<%= Url.Content ("~/Img/myImage.jpg") %>"

for more info :

http://msdn.microsoft.com/en-us/library/system.web.ui.control.resolveurl.aspx

Best practices, How to specify relative path for css,javascript and images files?

Sign up to request clarification or add additional context in comments.

Comments

1

This is not really an ASP .NET issue, and more a job for IIS.

Don't make the mistake of assuming that you need to do everything with server controls. If you just want people to be able to download these files, a simple <a href='/yourstaticcontent'>link</a> will do, and is actually preferable to using a server-side control.

EDIT I agree with Massimiliano on expressing paths from the root.

1 Comment

I didn't make myself clear I think, I update the question. I am not interested in serving files for the user.
1

If you installed IIS/ASP.NET from the Control Panel, you might not have turned on static Content.

You'll find a checkbox for it in the Control Panel, Turn Windows Features On or Off: World Wide Web Services/Common HTTP Features/Static Content

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.