简体   繁体   English

Writing Asp.net web forms Application URL Like Asp.net MVC (that uses Razor ) URL

[英]Writing Asp.net web forms Application URL Like Asp.net MVC (that uses Razor ) URL

Greeting, pardon my maybe non important question, I am just trying to redecorate URLS that I am using in my Asp.net Web Forms application to be like Asp.net MVC apps that uses razor, the first step I've done is to remove the aspx successor and I am done with this but the second step is which I am trying is to replace pagename?id=someid with pagename/id or any formula except the usual formula, tbh the task eventually is to reduce the characters used in the ULR so removing.aspx will execlude 4 characters and the second approach will replace?id= with slash and renaming page with pagename+id like n1 will not hit the server as the page name would have been changed any suggestion is welcome. Greeting, pardon my maybe non important question, I am just trying to redecorate URLS that I am using in my Asp.net Web Forms application to be like Asp.net MVC apps that uses razor, the first step I've done is to remove the aspx successor and我已完成此操作,但我尝试的第二步是将 pagename?id=someid 替换为 pagename/id 或除常用公式之外的任何公式,最终任务是减少 ULR 中使用的字符,以便删除。 aspx 将排除 4 个字符,第二种方法将用斜杠替换?id= 并用 pagename+id 像 n1 重命名页面不会命中服务器,因为页面名称会被更改,欢迎提出任何建议。 I did the below change on my web.config to exclude aspx successor我对我的 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>

Update, I am able to find semi solution after few hours of searching and testing, I called it semi solution because ajax calls is no longer working, and any page that has update panel is showing error related to axd ,I used routing as the link below更新,经过几个小时的搜索和测试,我能够找到半解决方案,我称之为半解决方案,因为 ajax 调用不再起作用,并且任何具有更新面板的页面都显示与 axd 相关的错误,我使用路由作为链接以下

ASP.NET Routing with Web Forms ASP.NET 路由与 Web Forms

just added the below code to global.asax file刚刚将以下代码添加到 global.asax 文件中

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

and on my page I am redirecting as:在我的页面上,我重定向为:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM