zoukankan      html  css  js  c++  java
  • ASP.NET MVC2 实验总结

    1、以下4个DLL为MVC框架引用,在程序中将引用属性设为复制到本地。

    System.ComponentModel.DataAnnotations.dll
    System.Web.Abstractions.dll
    System.Web.Mvc.dll
    System.Web.Routing.dll
    

      

    2、按如下修改,并在开发时注意所有链接使用Url.Action方法来得到,将使程序既可以在IIS5、6下运行,又能在IIS7下保持URL的美观

    Web.config的配置项按如下修改:

      <appSettings>
        <add key="controllerSuffix" value=".aspx"/>
      </appSettings>
    
       <authentication mode="Forms">
         <forms loginUrl="~/Account.aspx/LogOn" timeout="2880"/>
       </authentication>
    

      

    在根目录新建一个Default.aspx,此页只用来转向。内容如下:

    <%@ Page Language="C#" AutoEventWireup="true" %>

    <%
    string url = Request.Url.ToString();
    string query = string.Empty;
    if (url.IndexOf("?") >= 0)
    query = url.Substring(url.IndexOf("?"));
    string controllerSuffix = ConfigurationManager.AppSettings["controllerSuffix"];
    Response.Redirect("/Home" + controllerSuffix + "/Index" + query);
    %>

    路由注册按如下方法写:

            private static string ControllerSuffix = ConfigurationManager.AppSettings["ControllerSuffix"];
    
            public static void RegisterRoutes(RouteCollection routes)
            {
                routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    
                routes.MapRoute(
                    "Default", // Route name
                    "{controller}" + ControllerSuffix + "/{action}/{id}", // URL with parameters
                    new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
                );
            }
    

      

    3、以上设置在IIS6下能运行,但不能像IIS7下有那样美观的URL,要想做到还需要进一步设置(虚拟主机就没这权限了)

    在站点属性中的“主目录”--》“配置”。在下方的“通配符应用程序映射”中插入一个映射,可执行文件交给.NET的“aspnet_isapi.dll”,默认地址一般在“C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll”

  • 相关阅读:
    IOS
    XCode
    Android Studio
    Android Studio
    Cordova
    Delphi
    Cordova
    Delphi
    JQuery Mobile
    twitter ads_campaign management(图示)
  • 原文地址:https://www.cnblogs.com/yvesliao/p/1765724.html
Copyright © 2011-2022 走看看