asp.net副檔名不顯示並獲得URL值

來源:互聯網
上載者:User

標籤:選擇   charset   images   html   prot   命名空間   web   .com   方法   

由vs2013建立“web表單應用程式”的網站,URL不顯示副檔名。那今天就實現該功能

1、首先開啟vs2013>建立項目>如選擇

2、選擇項目右擊>管理NuGet程式包>在搜尋方塊輸入(FriendlyUrls),搜到後點安裝(接受協議後安裝完成):

3、注意閱讀readme.txt,在解決方案

4、開啟RouteConfig(路由配置)和MVC裡的路由一樣,把原來的代碼修改了,

修改後:

5、選擇項目右擊>添加>建立項>全域應用程式類(Global.asax)設定如下:

添加如下代碼是程式在啟動時執行該方法(需引用的自己引用)

protected void Application_Start(object sender, EventArgs e)        {            RouteConfig.RegisterRoutes(RouteTable.Routes);        }        protected void Application_Error(object sender, EventArgs e)        {        }           protected void Application_End(object sender, EventArgs e)        {        }
View Code

 6、建立一個測試web表單(test.aspx)可以什麼都不用寫,效果如下:

7、獲得url值:

注意!引用命名空間:

<%@ Import NameSpace="Microsoft.AspNet.FriendlyUrls" %>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="urlTest.test" %><%@ Import NameSpace="Microsoft.AspNet.FriendlyUrls" %><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>    <title></title></head><body>    <form id="form1" runat="server">        測試視窗        <% foreach (var segment in Request.GetFriendlyUrlSegments()) { %>            <p><%: segment %></p>        <% } %>    </form></body></html>
View Code

這些可以做在後台,效果如下:

 

asp.net副檔名不顯示並獲得URL值

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.