2013-04-18 136 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