DNS and MVC 5 routing (Internet vs Internal Lan) - asp.net-mvc-5

I know there are many helps on MVC 5, but I have not seen the following question answered.
My application works fine on the local LAN... I can access using expected URL:
http://www.mycompany.com/myapp
However when I try to access the server over the INTERNET I can't access the application via the hostname, only via the external IP address:
http://xx.xx.xx.xx/myapp
I have talked to the firewall / DNS admin people and the assure me that it is an application problem. We are using GoDaddy to handle DNS. The admin has setup and A record to point to the server, but after working with GoDaddy they have setup subdomains as the way to access applications...
They have another Internet application (that uses asp.net) working using the following URL:
http://appname.companyName.com
This is the way they expect my application to route on the Internet...
I am using just the standard default MVC routes... since my application routes correctly on the local lan I assumed the problem is with the DNS ... and the admin people say it is an MVC problem...
So what is the problem and what is the solution? Are the DNS / Firewall admin poeple right? Is this an issue caused by my MVC routing?
Here is my standard RouteConfig.cs file... I don't have anything special setup...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
namespace EtracsWeb
{
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{resource}.aspx/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
}

Related

Getting http 404 Error when creating a MVC 5 Empty Controller and in the browser giving the url to the controller

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace IndentityDemo.Controllers
{
public class SecretController : Controller
{
//
// GET: /Secret/
public ContentResult Secret()
{
return Content("This is secret...");
}
}
}
I'm writing code in VS2013. I've created a controller named SecretController.
After build.. I've write url in browser .. "http://localhost:14516/Secret/Secret" but it give me the Error as bellow:
Server Error in '/' Application.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /Secret/Secret
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.1586.0
My HomeController Working fine. But Controller can't be reached. Even when I attach a break point to the controller method it giving me a warning that 'The breakpoint will not currently be hit'
Please help me resolve this problem.
Try to add:
public SecretController() { }
before your Secret()

Web API Owin self host multiple applications

We are trying to setup an owin self host service for multiple applications (app1, app2).
We'd like to use the same behavior of IIS where one application pool uses one AppDomain per application.
Here is the code we use:
using (WebApp.Start<WebServerStartup>(url: "http://localhost:9000/")) { ... }
... and the WebServerStartup implementation:
internal class WebServerStartup
{
public void Configuration(IAppBuilder appBuilder)
{
// Configure Web API for self-host.
var config = new HttpConfiguration();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
appBuilder.UseWebApi(config);
}
How can we use multiple AppDomains for each application? Is there a way to declare multiple webapps using Webapp.Start(...) in separate AppDomains that would share the same port? Or is there some way to route the requests to various appdomains somehow by defining a route like app/api/{controller}/{id} instead of api/{controller}/{id}?
Thanks
There's no built in support for running the apps in separate domains. You'd want to start each new AppDomain and then run WebApp.Start inside.

IIS 8.5 MVC 5 Routes 'api/controllerName' gives 404 Not Found Error

Within a MVC 5 Webapi project, I am trying to do a GET request via jquery using URL 'api/controllerName'. The web application is hosted under Default Website and the root of the webisite is "localhost/myApp".
The route 'api/controllerName' gets translated to 'localhost/api/controllerName' instead of 'localhost/myApp/api/controllerName' throwing 404 Not found Error.
This has to do something with IIS 8.5 and MVC 5 routing, because:
The Same setup works well on IIS 7.5
The same set up works well on IIS 8.5 if i do not use a virtual directory and host the application directly at Default Web Site.
My Global.asax.cs's RegisterRoutes Method looks like below
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
I figured this out. Apparently, IIS 7.5 worked fine with the bare route 'api/controllerName' but IIS 8.5 needed a fully qualified route created using #Url.RouteURL utility with RouteName as "DefaultApi".
i replaced the URL with
'#Url.RouteUrl("DefaultApi", new { httproute = "", controller = "controllerName"})'
and it worked like a charm (on both IIS 7.5 and IIS 8.5).

How to set up Redis cache for Fireworks app on Azure?

I downloaded the sample fireworks app from
https://github.com/WindowsAzure-Samples/Fireworks
And then deploy it to Azure. But it does not work. I suspect I did not initialize it properly.
Could anyone please help?
Here're the errors:
And my init code:
using System;
using System.Threading.Tasks;
using Microsoft.Owin;
using Owin;
using Microsoft.AspNet.SignalR;
[assembly: OwinStartup(typeof(Firework.Startup))]
namespace Firework
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
GlobalHost.DependencyResolver.UseRedis("fireworks.redis.cache.windows.net", 6379, "UaI+1bJq79dTEJiP0jZHAcBRLjT+lR9rXTxtUl1op1o=", "Fireworks");
app.MapSignalR();
}
}
}
My Azure:
Update 1: Is there a way for me to enable the Non-SSL port.
You have the non-SSL port (6379) disabled in the Azure portal, but that's the port you're trying to connect to in your code. I would suggest enabling that port first and ensure it works without SSL, then try to get the app running on the SSL port (6380) after that.

Best practice for SharePoint vanity url/redirection

My employer uses MOSS 2007 for our company intranet. It runs solely on secure http and is also exposed to the outside world via ISA. I currently have a request to add a forwarding URL to our site so that something like the following will occur:
intranet.mycompany.com/vanityname
redirects to ->
intranet.mycompany.com/somedeeplink/default.aspx
I fully expect this sort of thing will become more popular with our users as time goes on. So I am looking for a solution that scales. I have read various articles about creating a /site/ with forwarding meta tags or a forwarding SharePoint page type. I've also seen some that talk about adding virtual directories, etc directly in IIS. All these solutions seem to be overkill and inevitably take up more memory or processing time on the web servers.
I am currently leaning towards writing an http module that can be configured in the web.config and perform redirects. I wanted to get feedback to see if anyone else has done something similar in SharePoint 2007 and had any suggestions. Again, I'd like to implement something that scales without making major changes later on and is going to put minimal processing burden on our web servers. Thanks!
Ive implemented url redirecting with MOSS using the HTTP module route. I documented the code I used and what parameters worked the best for me here;
http://scaredpanda.com/2008/08/url-rewriting-with-sharepoint-moss-2007/
Take a look and let me know if this helps you and if you have any questions.
Update: The link above is no longer valid, so here text from the page that I used for URL redirect.
After messing around for a little bit it, I came up with a good way to do it. When I was looking for examples on the web there were a lot of people saying that it couldnt be done. But in the end it actually didn’t take much to implement it. Here’s an HttpModule that I wrote to do the work.
The key pieces are the this.app.BeginRequest += new EventHandler(app_BeginRequest) which
steps in front of the request and allows the module to get its redirect on.
And HttpContext.Current.RewritePath(redirect, false); will push the necessary headers n such forward so that the receiving .aspx page will understand how to correctly post back.
using System;
using System.Data;
using System.Data.SqlClient;
using System.Reflection;
using System.Collections;
using System.Text;
using System.Web;
using System.Web.Caching;
using System.Web.SessionState;
using System.Security.Cryptography;
using System.Configuration;
using System.Threading;
using System.IO;
using System.Security;
using System.Security.Principal;
namespace ScaredPanda
{
public sealed class RewriteHttpModule : IHttpModule
{
HttpApplication app = null;
///
/// Initializes the httpmodule
///
public void Init(HttpApplication httpapp)
{
this.app = httpapp;
this.app.BeginRequest += new EventHandler(app_BeginRequest);
}
public void app_BeginRequest(Object s, EventArgs e)
{
try
{
//determine if the income request is a url that we wish to rewrite.
//in this case we are looking for an extension-less request
string url = HttpContext.Current.Request.RawUrl.Trim();
if (url != string.Empty
&& url != "/"
&& !url.EndsWith("/pages")
&& !url.Contains(".aspx")
&& url.IndexOf("/", 1) == -1)
{
//this will build out the the new url that the user is redirected
//to ie pandas.aspx?pandaID=123
string redirect = ReturnRedirectUrl(url.Replace("/", ""));
//if you do a HttpContext.Current.RewritePath without the 'false' parameter,
//the receiving sharepoint page will not handle post backs correctly
//this is extremely useful in situations where users/admins will be doing a
//'site actions' event
HttpContext.Current.RewritePath(redirect, false);
}
}
catch (Exception ex)
{
//rubbish
}
}
}
}
Have you looked into Alternate Access Mappings?
http://technet.microsoft.com/en-us/library/cc263208.aspx
If you are open to paying for a solution. Have a look:
NOT FREE -> http://www.muhimbi.com/Products/SharePoint-URL-Shortener.aspx
Depending on the number of redirects you might want to implement an HTTP module as stated) but how about checking out
FREE -> http://www.codeplex.com/sharepointsmart404
Use the URL Rewrite feature in IIS. (I believe it's an IIS 7 extension)
http://www.iis.net/download/urlrewrite

Resources