从c#代码创建aspx页面

本文关键字:aspx 页面 创建 代码 | 更新日期: 2023-09-27 18:09:05

我希望得到一个关于如何从代码后(c#)创建一个动态asp.net页面的方向。例如,一个用户上传了一张名为"flower.jpg"的图片,我希望创建一个自定义的动态asp.net页面,将其命名为"flower.jpg.aspx"。我不知道怎么做,我真的需要一个方向。

从c#代码创建aspx页面

首先,我不认为你需要创建一个新的页面,这是一个相当简单的问题来解决,如果你使用以下:

    利用你可以在ASP中做动态操作这一事实。净
  • 上传所有文件到DB, File等,并保持一个引用

  • 创建一个类,它将包含用于上传的元数据

  • 当需要数据时,调用显示用户上传的项目元数据的页面。g姓名、地点、时间等)
  • 用户ASP。. NET路由如果你想让链接反映照片名称

您不应该为每个图像创建aspx页面,因为如果您这样做,您将不得不将aspx页面放在您的虚拟目录中,这将导致网站重新启动。

您可以将图像保存到数据库或文件系统中,并在数据库中存储图像属性,如扩展名,文件名,大小,并有一个页面列出图像,另一个页面查看图像细节。

详细信息页面将有一个<img src="URL to the Image"/>标记,该标记将显示图像和其他一些属性。

如果必须使用。aspx扩展名的页面,那么你可以使用路由,如果你使用MVC,你将有一个单一的MVC控制器和动作,但你将有一个路由的形状:{Controller}/{action}/{image}.aspx

通过检查你的描述,我认为你想做的是创建一些照片库页面。您可能会对这些资源感兴趣:

http://www.codeproject.com/Articles/14290/Simple-Photo-Gallery-With-ASP-NET-2-0http://weblogs.asp.net/bleroy/a-simple-asp-net-photo-albumhttp://www.codeproject.com/Articles/21075/Gallery-Server-Pro-An-ASP-NET-Gallery-for-Sharing

在网上。设置setpath到你的images:

<appSettings>
    <add key="PicRootPath" value="~/PICStore/"/>
    <add key="PicRootDefaultPath" value="~/PicStore/Default/" />
</appSettings>

创建类ContentInfoLoader,如:

Configuration rootWebConfig = 
    WebConfigurationManager.OpenWebConfiguration("~/");
if(0<rootWebConfig.AppSettings.Settings.Count)
{
    KeyValueConfigurationElement picRootElement = 
        rootWebConfig.AppSettings.Settings["PicRootPath"];
    if(null!=picRootElement)
    {
        _picRootPath=picRootElement.Value;
    }
    picRootElement = rootWebConfig.AppSettings.Settings["PicRootDefaultPath"];
    if (null != picRootElement)
    {
        _picRootDefaultPath = picRootElement.Value;
    }
}
然后是获取图像的方法:
public string[] GetGalleryPaths(string picRootRealPath) 
{
    if (Directory.Exists(picRootRealPath))
    {
        return Directory.GetDirectories(picRootRealPath);
    }
    else
    {
        return null;
    }
}
public string[] GetPhotoList(string galleryName, string picRootRealPath)
{
    string galleryPath=picRootRealPath + "''" + galleryName + "''pics";
    if (Directory.Exists(galleryPath))
    {
        return Directory.GetFiles(galleryPath,"*.JPG");
    }
    else
    {
        return null;
    }
}