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?
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
DNN does have a Host setting that will allow or deny access to users logging in based on their IP address. It's in Host Settings > Advanced Settings > Login IP Filters. I don't think that will give you the desired result.
I would not suggest creating a module. It can be difficult copying it to all pages and ensuring one instance is added to every page.
Rather, I would create a skin (theme) token. To do this, create a simple class library project. Create an .ascx and ascx.cs file. You can leave the .ascx empty because you don't have any html to add to the pages. In the .cs, put something like this:
namespace MyCompany.DNN.Skin
{
public partial class IpRedirect : SkinObjectBase
{
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
// Put your redirect logic here
}
}
}
Then, in your theme/skin ascx pages, include the following:
<%# Register TagPrefix="myco" TagName="IPREDIRECT" Src="~/DesktopModules/MyCompany/IpRedirect/IpRedirect.ascx" %>
<myco:IPREDIRECT ID="pageRedirect" runat="server" />
This will ensure that this functionality will execute on all pages in the site that use the skin/theme.
Related
I am about to move a webshop from old webforms to new .Net Core (.Net 5) site.
The old urls have a lot of good rating on google and I would like to be able to make a permanent redirect from an aspx page to .net core page.
Etc.:
www.mydomain.com/products/great-backpack-1234.aspx
to
www.mydomain.com/great-backpack
I believe that requires that I have both .net core and aspx site running on the same domain.
Is this possible?
Or do any one have any other solution ideas?
Best regards
Thats probably not needed to run both on the same domain or space. It seems everything will end in .aspx, and assuming you are using MVC, a controller function to catch-all requests that don't match other routes, then check to see if it ends in aspx, should do it for you. You can put it in an existing controller, but I personally would put it in a new one to separate concerns
public class RedirectController : Controller
{
[Route("{**url}", Order = 999)]
public IActionResult RedirectPage(string url)
{
//Redirect logic based on the URL given, making sure it ends in aspx
}
}
The url would come across in the url parameter as a string and you can check to see if it ends in aspx, and what the page name was to determine where to send them. So "www.mydomain.com/products/great-backpack-1234.aspx" would come across in the url parameter as "products/great-backpack-1234.aspx". Note that the order field in the route attribute assures that it will be the last match checked for patterns, so it shouldn't mess with anything else.
I am using IdentityServer3 for authentication. Users are stored using AspnetIdentity framework. I wanted to provide reset password functionality to users. I want to provide this functionality in IdentityServer hosting application. I have gone through several posts here here here and this what I have done so far:
1>I have created custom user service derived from AspNetIdentityUserService.
2>Created resetpassword.html and put it in template folder. (documentation)
3>It's not necessary to create a CustomViewService, so I added LoginPageLink in AuthenticationOptions and now the link is available on login page.
4>Created ResetPasswordController
public class ResetPasswordController : Controller
{
public ActionResult Index()
{
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult ResetPassword(string username)
{
// call customservice here and reset password
return View();
}
}
Issue
when i click on the resetpassword link, i get error
The view 'Index' or its master was not found or no view engine
supports the searched locations. The following locations were
searched: ~/Views/resetpassword/Index.aspx
~/Views/resetpassword/Index.ascx ~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx ~/Views/resetpassword/Index.cshtml
~/Views/resetpassword/Index.vbhtml ~/Views/Shared/Index.cshtml
~/Views/Shared/Index.vbhtml
I know why the error is, its because we don't have corresponding view in Views folder where MVC framework in looking for. My view resetpassword.html is in template folder. And that's the confusion. Identity server is using Angular to build its views.
If I decide to use angular then
1>How do I create and pass model to resetpassword.html.
2>How do I wire-up my CustomUserService to controller.
If I use ASP.NET MVC then
1>I need to add resetpassword.cshtml in Views folder and also a new Layout.cshtml in shared folder.
2>Doing so MVC scafolding will add bootstrap resources (css,js, jquery). The version may not match with IdentityServer's embedded resources.
I am comfortable coding ASP.NET MVC but worried adding bootstrap resources twice in the solution.
What is the best and easy approach here. Any sample example will be greatly appreciated.
I am trying to redirect my company's home page (let's call it example.com) to a new webpage I built : example.net, without losing any archive and sub pages, i.e when a user navigates to example.com it will redirect to example.net, but when they click on "about us" I want it to go back to example.com/aboutus.
I can get it to redirect but every time a user clicks on a link (such as about us) the browser will try to load example.net/aboutus rather than example.com/aboutus, which does not exist.
I have tried many different redirect commands, 301 commands, .htaccess as well as adding redirects to the index page. Everytime I get the homepage to open to the new URL
I have attached my index page code.
<?php
/**
* Copyright 2013
* #author
*/
include_once($_SERVER["DOCUMENT_ROOT"]."/example.php");
//print_r($_SERVER);
$pageArr = explode("/", $_GET["q"]);
$_GET["q"] = $pageArr[0];
if($pageArr[1]){
$_GET["z"] = $pageArr[1];
}
if(!$_GET["q"]){
$_GET["q"] = "home";
}
$mDevice = null;
if($_GET["print"] == "true"){
$mDevice = "standard";
}
//Begin defining the main page
$WebPage = new xyWebpage($_GET["q"], $mDevice);
//$WebPage->setCharset("ISO-8859-1");
showPage();
function getPageName(){
return $_GET["q"];
}
?>
I'm not a PHP guy, but depending on your platform you can use either:
MOD_REWRITE Module for Apache or IIS re-write module.
Both of these support re-writing URL's which can match your use case.
I'm curious why you would just not replace your home page that you are redirected from on the same server(s), but in any case, since you already have the redirect working you only need it on the .net server. You will need two rules, one to stop processing if it's a root URL request, and then one for all other requests that will re-write the root back to your .com address. You need that first rule so you don't create a loop between your servers.
I'm working on a new Joomla site and am working on testing outgoing email. I'd like to be able to intercept all outgoing emails and reroute them to an address I specify. It is very useful in development when you have a copy of a live site with thousands of users, so email does not go to real users from the copy site.
It would be great to do this with a extension but have been unable to find one to do some. I'm also open to getting this done on the server side if necessary.
I found a Drupal module that does exactly what I'd like to do except it's obviously for Drupal and note Joomla.
https://drupal.org/project/reroute_email
On Joomla-Level you could create a system plugin that loads up own, monkey-patched JMail class.
I'm not sure if you would be able to extend the original JMail because of namespace conflict, so maybe you'd have copy it over and alter the addRecipient method:
public function addRecipient($recipient, $name = '')
{
$this->add('custom#email.com', 'custom name', 'AddAddress');
return $this;
}
References:
Related Stack Overflow answer: How to override core classes
Gist: plgSystemOverrides
I am using Zend Framework to develop some application. I develop on my localhost and then I upload it to some subdomain like abc.mydomain.com. When I upload my layout index.phtml, I get the following for all URLs:
abc.mydomain.com/css/base.css 404 (Not Found)
on the web browser console but my CSS is in the public folder.
my code to link this css is :
<?php echo $this->headLink()->appendStylesheet('/css/base.css') ?>
What should i do to make these addresses work ?
To complete my question : How does the framework distinguish between a folder and a controller or How could i tell the framework to don't act on these URL ass action , they are folders ?
Sounds like a mapping issue associated to the hosting the subdomain. Often on shared hosting you cannot map the project's public folder to the subdomain. So a variety of rewrite tricks are required to map requests for pages and assets into the right directories without confusing ZF about the requested URL.
Check out:
http://www.papayasoft.com/2010/05/08/zend-framework-shared-hosting/
for a description of the problem and various approaches to solving it.
Usually, the baseUrl() view-helper detects (internally, using the Zend_Controller_Front::getBaseUrl() method) what your app's base-url is.
But sometimes, depending upon your vhost setup and the location of your public folder within the doc root - you need to tell the app explicitly what your base-url is.
In application/configs/applicatiom.ini, you can set:
resources.frontController.baseUrl = "http://abc.mydomain.com"
Then in a view-script, you can access public assets using the baseUrl() view-helper and a relative url (relative to the base you set), as follows:
<?php echo $this->headLink()->appendStylesheet($this->baseUrl('css/base.css')) ?>
though I see many people use it as a prefix-only:
<?php echo $this->headLink()->appendStylesheet($this->baseUrl() . '/css/base.css') ?>