Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Asp.Net+;C#_C#_Asp.net - Fatal编程技术网

在Asp.Net+;C#

在Asp.Net+;C#,c#,asp.net,C#,Asp.net,我有一个简单的web表单应用程序。我有一个名为“show.aspx”的页面,负责按文章Id显示我的文章 起初,我使用QueryString获取文章Id,并根据该Id显示文章。然而,我知道这个url对SEO不友好 我的URL是这样的:mysite.com/article/show.aspx?articleid=7737 所以我决定转向URL重写,但因为我在这方面没有经验,所以我最终使用了URL路由技术 所以现在我的url是这样的:mysite.com/article/7737/ 它很好用。我使用在

我有一个简单的web表单应用程序。我有一个名为“show.aspx”的页面,负责按文章Id显示我的文章

起初,我使用QueryString获取文章Id,并根据该Id显示文章。然而,我知道这个url对SEO不友好

我的URL是这样的:mysite.com/article/show.aspx?articleid=7737

所以我决定转向URL重写,但因为我在这方面没有经验,所以我最终使用了URL路由技术

所以现在我的url是这样的:mysite.com/article/7737/ 它很好用。我使用在global.asax文件中定义的{articleid}参数获取article的值

但我想得到我的url如下: mysite.com/article/article-title-from-database/

是否可以从数据库中获取标题并在每个单词之间使用连字符重新写入url

如果我需要传递两个参数,例如: 第/{articleid}/{title}条/

下面是我的Global.asax

<%@ Application Language="C#" %>
<%@ Import Namespace="System.Web.Routing" %>

<script runat="server">
    void Application_Start(object sender, EventArgs e) 
    {
        RegisterRoutes(RouteTable.Routes);
    }
    void RegisterRoutes(RouteCollection routes)
    {
        routes.MapPageRoute("ArticleDetails","article/{articleId}", "~/article/show.aspx");
    }

</script>

可能重复的Well@GaryWalker该解决方案似乎与我的问题相似,但看起来很复杂。我刚刚开始探索URL路由,所以这对我来说是全新的。任何好的解释/演示/视频讲座都将不胜感激。@askBittu你知道,你是否认为它看起来很复杂是无关紧要的-这是解决方案。主要问题是ASP.NET Webforms是一种非常过时的技术,因此有很多限制。每个人都试着离开很多代人,现在都在MVC上——MVC中有很好的URL。传递id或一些文本作为参数并没有区别。但是空间角色并不是你唯一需要担心的,还有其他的(?*,等等)亲爱的@Kuzgun,我也想到了传递标题作为参数。我可以通过删除非法字符来转换文章的标题,并可以将其用作参数。但这会增加出错的机会。我还是很困惑。
protected void Page_Load(object sender, EventArgs e)
    {
        if (RouteData.Values["articleId"].ToString() != string.Empty)
        {
            Articles.rptArticle = rptDisplayArticle;
            Articles.rptHashTags = rptHashTags;
            Comments.rptComments = rptDisplayComments;
            Articles.articleId = RouteData.Values["articleId"] as string;
            Articles.Show();
            if (!Comments.show())
            { 
                lblNoComments.Text = "NO COMMENTS";
            }
            if (Authorization.Authorize())
            {
                panCommentPost.Visible = true;
                ltLoginPrompt.Text = "POST A COMMENT";
            }
        }
        else
        { Server.Transfer("~/404.html"); }