• asp.net mvc5 伪静态


    asp.net mvc5 伪静态 WebForm

    Mvc4和5通用

    1、背景:老项目WebForm开发 需要 融合到新项目Mvc5开发

    2、需求:Url地址TruckDetail.aspx?id=455 达到效果 truck/455.html

    3、不是最佳方案,但是个过度项目所以达到效果ok,欢迎丢转。

    第一步:继承IRouteHandler

    复制代码
    public class OldWebFormsRouteHandler : IRouteHandler
        {
            private string pageName = string.Empty;
            private string id = string.Empty;
            public IHttpHandler GetHttpHandler(RequestContext requestContext)
            {
                
                pageName = requestContext.RouteData.GetRequiredString("oldPageName");
                id = requestContext.RouteData.GetRequiredString("id");
    
                string path="/Pages/" + this.pageName + ".aspx";
    
                IHttpHandler MyHander = BuildManager.CreateInstanceFromVirtualPath(path, typeof(System.Web.UI.Page)) as IHttpHandler;
                return MyHander;
            }
        }
    复制代码

    第二步:在默认规则前ADD 注意.html

    复制代码
    public class RouteConfig
        {
            public static void RegisterRoutes(RouteCollection routes)
            {
                routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    
                routes.Add("MyRoute", new Route("{oldPageName}/{id}.html", new OldWebFormsRouteHandler()));
    
                routes.MapRoute(
                    name: "Default",
                    url: "{controller}/{action}/{id}",
                    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
                );
            }
        }
    复制代码

    第三步:修改Web.config

    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
    </system.webServer>

    第四步:aspx页面获得参数Request.QueryString["id"]换成RouteData.Values["id"]

    复制代码
    <form id="form1" runat="server">
        <div>
        
            id:<%=RouteData.Values["id"]==null?"yy":RouteData.Values["id"].ToString() %><br />
            oldPageName:<%=RouteData.Values["oldPageName"]==null?"no":RouteData.Values["oldPageName"].ToString() %>
    
        </div>
    </form>
    复制代码

    效果:

    转载请注明来源地址:http://www.cnblogs.com/huangyoum/p/4154338.html

  • 相关阅读:
    plt/sns draw histgram
    normalization, standardization and regularization
    DTU DeepLearning: exercise 7
    DTU DeepLearning: exercise 6
    pytorch save model + Gmatch4py + jupyter debugger + community structure
    GCN
    networkx graph save and load
    DeepLearningDTU: Building a RNN step by step
    通过属性找方法,传参数
    react语法
  • 原文地址:https://www.cnblogs.com/zengpeng/p/5899885.html
Copyright © 2020-2023  润新知