Donate

Get Absolute Server Path Of Resources In ASP.NET MVC

In a scenario where you want to load images or other resources, Url.Content() does not return the exact resource path like this (D:\Cart\CartProject\Images\Item4.jpg). Hence, resulting into a null exception or empty resource.

Instead of using Url.Content() or ResolveUrl(), i get the server path of the resource using HttpContext of the application.
return new ImageResult(HttpContext.Server.MapPath("~/Images/Item" + id + ".jpg"));
Note: Testing is done locally and not on a virtual directory...

Source: Find Absolute Path the the App Data Folder from Controller Cheers!

Comments

Donate

Popular Posts From This Blog

WPF CRUD Application Using DataGrid, MVVM Pattern, Entity Framework, And C#.NET

How To Insert Or Add Emojis In Microsoft Teams Status Message

Bootstrap Modal In ASP.NET MVC With CRUD Operations