【问题标题】:Writing Asp.net web forms Application URL Like Asp.net MVC (that uses Razor ) URL编写 Asp.net Web 表单应用程序 URL 像 Asp.net MVC(使用 Razor)URL
【发布时间】:2021-07-30 06:07:03
【问题描述】:

问候,请原谅我可能不重要的问题,我只是想重新装饰我在 Asp.net Web Forms 应用程序中使用的 URL,就像使用 razor 的 Asp.net MVC 应用程序一样,这是我完成的第一步是删除 aspx 继任者,我已经完成了这个,但我正在尝试的第二步是将 pagename?id=someid 替换为 pagename/id 或除常用公式外的任何公式,最终任务是减少 ULR 中使用的字符,因此删除 .aspx 将排除 4 个字符,第二种方法将替换 ?id= 与斜杠 并且像 n1 这样使用 pagename+id 重命名页面不会访问服务器,因为页面名称会被更改 欢迎任何建议! 我在 web.config 上进行了以下更改以排除 aspx 继任者

<system.webServer>
        <rewrite>
            <rules>
                <rule name="RewriteASPX">
                    <match url="(.*)" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="{R:1}.aspx" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>

【问题讨论】:

    标签: asp.net web concept web-technologies


    【解决方案1】:

    更新!经过几个小时的搜索和测试,我能够找到半解决方案, 我称之为半解决方案,因为 ajax 调用不再起作用,并且任何具有更新面板的页面都显示与 axd 相关的错误,我使用路由作为下面的链接

    ASP.NET Routing with Web Forms

    刚刚将以下代码添加到 global.asax 文件中

    protected void Application_Start(object sender, EventArgs e)
            {
                RegisterRoutes(RouteTable.Routes);
            }
            void RegisterRoutes(RouteCollection routes)
            {
                   routes.MapPageRoute(
                    "mypage",
                    "mypage/{Name}",
                    "~/mypage.aspx"
                                      );
             }
    

    在我的页面上我重定向为:

    Response.Redirect(GetRouteUrl("mypage", new { Name = "myparam" }));
    

    【讨论】:

    • 上述解决方案有效,但如果我有更新面板,我有脚本管理器错误 axd,未捕获错误:ASP.NET Ajax 客户端框架无法加载。
    猜你喜欢
    • 1970-01-01
    • 2011-03-05
    • 1970-01-01
    • 2011-10-31
    • 2010-09-21
    • 2018-08-07
    • 1970-01-01
    • 2018-12-30
    • 1970-01-01
    相关资源
    最近更新 更多