Allow Requests to App

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


这是不推荐的,因为应用程序数据是用于应用程序文件的,但可以通过将以下行添加到配置文件来完成

  <system.webServer>
    <security>
      <requestFiltering>
        <hiddenSegments>
          <remove segment="app_data" />
        </hiddenSegments>
      </requestFiltering>
    </security>
  </system.webServer>
链接地址: http://www.djcxy.com/p/7256.html

上一篇: 表单身份验证会提供太长的查询字符串

下一篇: 允许请求应用程序