2013-04-18 122 views
1

我有兩種用戶類型:讀者和作者。我使用Reader.MasterAuthor.Master作爲授權用途。ASP.NET頁面命名使用母版頁

然後,有StoriesR.aspx繼承自Reader.MasterStoriesA.aspx繼承自Author.Master。 (在StoriesR.aspx頁,你能讀故事和StoriesA.aspx你能寫的故事。)所以,

  1. Reader.Master - >StoriesR.aspx
  2. Author.Master - >StoriesA.aspx

現在,問題是我不希望我的用戶在其瀏覽器中看到StoriesR.aspx?s=3StoriesA.aspx?s=3。我只希望他們看到stories?s=3。 (即使沒有.aspx部分)

我該如何做到這一點?

回答

1

您可以有一個aspx頁面,並根據用戶的類型(作者或讀者)以編程方式更改母版頁。

您可以在aspx頁面的Page_PreInit事件中執行此操作。

檢查this c# examplethis VB example

2

你可以從web.config文件中做到這一點使用urlMappings

加入web.confing

<system.web> 
    <!-- 
     Set compilation debug="true" to insert debugging 
     symbols into the compiled page. Because this 
     affects performance, set this value to true only 
     during development. 
    --> 
    <urlMappings enabled="true"> 
     <add url="~/reader/stories" mappedUrl="~/reader/StoriesR.aspx"/> 
     <add url="~/author/stories" mappedUrl="~/author/StoriesA.aspx"/> 

這將做URL映射。

+1

我不想在查詢字符串中使用「〜/ reader/stories」和「〜/ author/stories」。 – Sait