I want to allow users to request files located in App_Data Folder. This is the error:
Error Summary
HTTP Error 404.8 - Not Found
The request filtering module is configured to deny a path in the URL that contains a hiddenSegment section.
Its not possible to access App_Data
folder directly as it is used as data-storage for web application, for security reasons of the stored data you can access database from it only using connectionstring.
web.config
<connectionStrings>
<add name="AddressBookConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\myDB.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
check this http://www.codeproject.com/Articles/31557/A-Beginner-s-Guide-to-ASP-NET-Application-Folders#h
UPDATE
Programatically we can access any file in web application and write it to response:
public class FileAccessHandler:IHttpHandler
{
public FileAccessHandler()
{
//
// TODO: Add constructor logic here
//
}
public bool IsReusable
{
get { return false; }
}
public void ProcessRequest(HttpContext context)
{
String FileName = Path.GetFileName(context.Request.PhysicalPath);
String AssetName = HttpContext.Current.Request.MapPath(Path.Combine(HttpContext.Current.Request.ApplicationPath, "App_Data/" + FileName));
if (File.Exists(AssetName))
{
context.Response.ContentType = "image/jpeg";
context.Response.BinaryWrite(File.ReadAllBytes(AssetName));
context.Response.End();
}
}
}
Download: App_Data access sample
This is not recommended as app data is meant for application files but this can be done by adding the following line to the config
<system.webServer>
<security>
<requestFiltering>
<hiddenSegments>
<remove segment="app_data" />
</hiddenSegments>
</requestFiltering>
</security>
</system.webServer>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With