귀하의 요구 사항에 따라 방금 구현 한 간단한 방법을 살펴보십시오. 같은 것을 할 수있는 더 많은 방법이있을 수 있습니다. 이 단지입니다
public class Global : HttpApplication
{
public static List<Images> col = new List<Images>();
private void GetImages()
{
// Build this collection as per your requirement. This is just a sample.
// Logic is to store current, next, previous image details for current displaying image/page.
// Hope while storing image each will have unique name before saving and will have all details in db like path, display name, etc.
col.Add(new Images("orderedList0.png", "orderedList0", "orderedList1", ""));
col.Add(new Images("orderedList1.png", "orderedList1", "orderedList2", "orderedList0"));
col.Add(new Images("orderedList2.png", "orderedList2", "orderedList3", "orderedList1"));
col.Add(new Images("orderedList3.png", "orderedList3", "orderedList4", "orderedList2"));
col.Add(new Images("orderedList4.png", "orderedList4", "", "orderedList3"));
}
void Application_Start(object sender, EventArgs e)
{
GetImages();
RegisterRoutes(RouteTable.Routes);
}
public static void RegisterRoutes(RouteCollection routeCollection)
{
routeCollection.MapPageRoute("RouteForImage", "Posts/{Name}", "~/Posts.aspx");
}
}
Posts.aspx
protected void Page_PreRender(object sender, EventArgs e)
{
string currentImage = RouteData.Values["Name"].ToString();
if (!String.IsNullOrEmpty(currentImage))
{
Images image = Global.col.Find(x => x.CurrentImage == currentImage);
// Get Current Image URL where actually it is stored using from image variable and render/set image path where you want to using image.CurrentImagePhysicalName
// Set Next - Previous Image urls
if (!String.IsNullOrEmpty(image.NextImage))
{
hyperlink_next.Visible = true;
hyperlink_next.Text = image.NextImage;
hyperlink_next.NavigateUrl = GetRouteUrl("RouteForImage", new { Name = image.NextImage });
}
else
hyperlink_next.Visible = false;
if (!String.IsNullOrEmpty(image.PreviousImage))
{
hyperlink_previous.Visible = true;
hyperlink_previous.Text = image.PreviousImage;
hyperlink_previous.NavigateUrl = GetRouteUrl("RouteForImage", new { Name = image.PreviousImage });
}
else
hyperlink_previous.Visible = false;
}
}
:
나는 클래스 생성 : 이미지
public class Images
{
public string CurrentImage { get; set; }
public string NextImage { get; set; }
public string PreviousImage { get; set; }
public string CurrentImagePhysicalName { get; set; }
public Images(string currentImagePhysicalName, string Current, string Next, string Previous)
{
this.CurrentImagePhysicalName = currentImagePhysicalName;
this.CurrentImage = Current;
this.NextImage = Next;
this.PreviousImage = Previous;
}
}
경로를 등록하고 응용 프로그램 시작시 이미지 수집을 초기화 샘플 데모. 여기서 주요 아이디어는 동적 URL을 처리하기 위해 RouteData.Values["Name"].ToString()
을 처리하는 것이 었습니다.
희망이 유용 할 것입니다.
슬러그를 생성하려면 다음을 확인하십시오. http://stackoverflow.com/questions/2920744/url-slugify-alrogithm-in-c 기존 유사 숫자에 따라 고유 슬러그에 대해 1,2,3에 번호 매기기 논리를 추가하십시오 데이터베이스에 슬러그. –