0
votes

I have publish my Web Application in IIS and I getting Error while running

Server Error in '/' Application.

Configuration Error Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: Could not load type 'SecurityHttpModule'.

My Web Config Like

    <httpModules>  
    <add name="SecurityHttpModule type="SecurityHttpModule"/>
    </httpModules>  

My SecurityHttpModule Like

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    public interface IHttpModule
    { }
    namespace BankSuite 
    {
    public class SecurityHttpModule : IHttpModule
    {
    public SecurityHttpModule() { }

    public void Init(HttpApplication context)
    {
        context.BeginRequest += new EventHandler(Application_BeginRequest);
    }

    private void Application_BeginRequest(object source, EventArgs e)
    {
        HttpContext context = ((HttpApplication)source).Context;
        string ipAddress = context.Request.UserHostAddress;
        if (!IsValidIpAddress(ipAddress))
        {
            context.Response.StatusCode = 403;  // (Forbidden)

        }
    }

    private bool IsValidIpAddress(string ipAddress)
    {
        return (ipAddress == "127.0.0.1");
    }

    public void Dispose() { /* clean up */ }
    }
    }
1
Your XML is not valid with the 3 x " ? - Alex K.
Why did you define your own IHttpModule? Anyway the name attribute must also contain the assembly name. - CodeCaster
Not Cleared to me,please share more details3 - Abhijit Ghosh
You can set IP restrictions at the IIS level. You can even add the restrictions directly in your web.config. Blocking IPs at the IIS level is cheaper than allowing the call to reach the web site. Do you really need to hand-code the same feature? - Panagiotis Kanavos

1 Answers

0
votes

It seems like you are missing a closing quote on the name make sure it is not like that in reall config

Try specify using Fully qualified name such as NamespaceQualifiedTypeName, AssemblyName

so something like BankSuite.SecurityHttpModule, AssemblyName - where AssemblyName correspond to your dll name

also if you are using iis 7+ with integrated mode, use

<configuration>
<system.webServer>
    <modules>
        <add name="SecurityHttpModule" type="BankSuite.SecurityHttpModule, AssemblyName"/>
    </modules>
</system.webServer>
</configuration>

instead.