2010-01-12 34 views
0

我試圖在asp.net MVC 1.0中實現一個customRoleProvider。這個類看起來像這樣roleManager在Default.aspx.cs中導致invalidOperationException

using System; 
using System.Web.Security; 



namespace Project.Web.Services 
{ 
    public class CustomRoleProvider: RoleProvider 
    { 
     public override bool IsUserInRole(string username, string roleName) 
     { 
      throw new NotImplementedException(); 
     } 
    public override string[] GetRolesForUser(string username) 
    { 
     throw new NotImplementedException(); 
    } 

    public override void CreateRole(string roleName) 


     { 
      throw new NotImplementedException();... 

我已經設置了Web.config文件如下

<configuration> 


<system.web> 

<roleManager enabled="true" defaultProvider="CustomRoleProvider"> 
    <providers> 
    <clear/> 
    <add name="CustomRoleProvider" type="Project.Web.Services.CustomRoleProvider" /> 
    </providers> 

</roleManager> 

...

當我這樣做,我得到Default.aspx中拋出一個InvalidOperationException異常。來自碼的httpHandler.ProcessRequest(HttpContext.Current);線以下

public partial class _Default : Page 
{ 
    public void Page_Load(object sender, System.EventArgs e) 
    { 
     // Change the current path so that the Routing handler can correctly interpret 
     // the request, then restore the original path so that the OutputCache module 
     // can correctly process the response (if caching is enabled). 

     string originalPath = Request.Path; 
     HttpContext.Current.RewritePath(Request.ApplicationPath, false); 
     IHttpHandler httpHandler = new MvcHttpHandler(); 
     httpHandler.ProcessRequest(HttpContext.Current); 
     HttpContext.Current.RewritePath(originalPath, false); 
    } 
} 

中描述了錯誤的CS如下所示 無法找到'索引'或其主人的視圖。以下地點搜索: 〜/瀏覽/首頁/的Index.aspx 〜/瀏覽/首頁/ Index.ascx 〜/查看/共享/的Index.aspx 〜/查看/共享/ Index.ascx

當我從Web.config文件中刪除roleManager問題消失,問題甚至reapears當我把以下行的Web.config

<roleManager enabled="false"></roleManager> 

是否有其他財產以後我需要做什麼?

回答

0

這可能不是您正在尋找的答案,但您可能會刪除default.aspx和default.aspx.cs,並且您的網站仍然有效。該文件僅用於某些Web服務器的某些配置,以便他們可以正確處理應用程序的根URL。

我建議您至少嘗試將文件重命名爲其他內容(例如backup.aspx)並查看您的網站是否仍然有效。如果確實如此,那麼你很好。

不幸的是,我不知道爲什麼你會得到這個特定的錯誤。

+0

嗨, 我試着重命名默認爲backupdefault,但是項目在啓動項目時仍然運行backupdefault頁面/類。有沒有其他人沒有這個問題? – Evan 2010-01-12 22:28:56

0

我發現問題的解決方案,首先出現的錯誤在某種程度上誤導了錯誤的實際原因。問題是我現在意識到有兩個Web.config文件;一個在Web項目下,另一個在Views文件夾中。我把代碼放到Web.config下,當我把它放到Web項目Web.config下時,沒有更多的錯誤。

相關問題