http-redirectdotnetnukedotnetnuke-moduleweb-user-controlsdotnetnuke-settings

Response redirect using IP in dotnetnuke


I am hosting and developer on my DNN portal. I need to redirect users using client IP. I think may be two ideas for this work.

1- DNN Setting

Maybe DNN has settings for it that I can set specific URL for client IP addresses and automatically DNN redirects to specific URL.

I read many topic but I could not find setting to do it.

Is there a way to do this?

2- New Module

I have a ascx that onload method has this code:

var IP = Server.HtmlEncode(Request.UserHostAddress).ToString();         
using (Entities db = new Entities())
{
    var retVal = db.URLAddresses.Where(u => u.IPAdress == IP).FirstOrDefault();
        if (retVal != null)
            Response.Redirect(retVal.URL);
}

But I should add this code to any ascx for redirect using client IP. This is impossible because maybe I haven't source code modules.

I think I should create new module. So I can add it to page. Module changes onload page and redirect to URL using client IP.

In this scenario, I try to create new module but I don't know how I can change onload method each page that is added module to it?


Solution

  • You can use IHttpModule and make a new Module for Including your class then you should add your IHttpModule to web.config . For e.g

          <add name="YourModule" type="YourAssembly, YourNameSpace" preCondition="managedHandler" />
    

    See this Sites: HTTP Handlers and HTTP Modules Overview and How To Create an ASP.NET HTTP Module