开发者

roleManager causes invalidOperationException in Default.aspx.cs

I'm trying to implement a customRoleProvider in asp.net MVC 1.0. The class looks开发者_如何学Python like this

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();...

I have setup the Web.config file as follows

<configuration>


<system.web>

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

</roleManager>

...

when i do this i get a InvalidOperationException thrown in Default.aspx.cs on the httpHandler.ProcessRequest(HttpContext.Current); line from the code below

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);
    }
}

the error is described as follows The view 'Index' or its master could not be found. The following locations were searched: ~/Views/Home/Index.aspx ~/Views/Home/Index.ascx ~/Views/Shared/Index.aspx ~/Views/Shared/Index.ascx

When I remove the roleManager from Web.config the problem goes away, the problem reapears even when i put the following line into the Web.config

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

Is there somthing else i need to do?


This might not be the answer you're looking for, but you can probably delete default.aspx and default.aspx.cs and your site will still work. That file is only needed for certain configurations of certain web servers so that they can handle the root URL of your application properly.

I recommend that at least as a test you try renaming the file to something else (e.g. backup.aspx) and see if your site still works. If it does then you're good to go.

Unfortunately, I don't know why you're getting this particular error.


I found a solution to the problem, firstly the error presented is somewhat misleading to the actual cause of the error. The problem was that i now realise that there were two Web.config files; one under the Web project and the other in the Views folder. I had put the code into Web.config under views when i should of put it under the Web projects Web.config, no more error.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜