I'm stuck, I'm really hoping someone can help or at least point me in the right direction. My end goal is to get my ASP.NET Core 2.1 app running on a CentOS Linux box. Since I'm using a mongo db in my actual app and wanted to eliminate any possible issues with that, I published a plain-jane asp.net core 2.1 mvc app, no authentication, and deployed it to a virtual host on my centos 7 box (apache upgraded via CoreIT to 2.4.37 since centos distros still deploy the older 2.4.6 version).
For the scope of this question I think I just need to make sure my reverse proxy is working properly and need help in pinning down that. I've followed instructions from here and the Microsoft setup doc from here. These 2 links are what I've been working with mainly.
When my app service is running, I can do a curl localhost:5000 and see the correct html of my homepage being returned. When I try from command line again with test.mydomain.com or test.mydomain.com:5000 it just times out. If I go to my app's conf (test.mydomain.com.conf in /etc/httpd/sites-available) and remove the ProxyPass, ProxyPassReverse and ProxyPreserveHost lines then I can hit test.mydomain.com from the outside with a browser and get my index.html file up and displaying properly (this is just one index.html file and not a part of the dotnet app though). It's only when I add the below back into my conf file it just hangs up when I try and hit the URL. I'm not sure what to look for in journalctl or maybe I should tail a specific log file to find out what it's waiting on and why it's taking so long.
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:5000/
ProxyPassReverse / http://127.0.0.1:5000/
Somehow is seems like my reverse proxy isn't set up right to be accessed from outside the box.
The rest of my app's config below.
<VirtualHost *:*>
RequestHeader set "X-Forwarded-Proto" expr=%{REQUEST_SCHEME}</VirtualHost>
<VirtualHost *:80>
ServerName test.mydomain.com
DocumentRoot /var/www/test.mydomain.com/public_html
ErrorLog logs/dashboard.crtv1.com.errorlog
CustomLog logs/dashboard.crtv1.com.access_log combined
</VirtualHost>
I think I addressed the issue although I'm not sure what issues I was actually having at the time of posting. I ended up through process of elimination and curl to find another service was running and using port 5000 in another virtual host - we're doing development and need a test, staging and production set of virtual hosts. Also I found I had some code in my app (UseUrls) that was specifically stating to use port 5000 so multiple copies of it within the same environment had resource conflicts. I'll circle back and update which environments will use which ports and hopefully have a nice set up.
In my local system I have published an Asp.net core Web app. How can i start a server from that folder which will listen to user request. I have tried Httplistener and Weblistener . But routing is not working in both case.
My http.sys code :
`
var builder = new WebHostBuilder().UseKestrel()
.UseStartup<Startup>()
.UseHttpSys(options =>
{
// The following options are set to default values.
options.Authentication.Schemes = Microsoft.AspNetCore.Server.HttpSys.AuthenticationSchemes.None;
options.Authentication.AllowAnonymous = true;
options.MaxConnections = null;
options.UrlPrefixes.Add("http://localhost:9000");
}).UseContentRoot(#"path to my publish folder")
.Build();
builder.Run();`
I am trying with http.sys . In this case I am able to start the server but routing is not working .
If you use windows, you can use Internet Information Server (IIS) to host an ASP.Net MVC application.
Please see link below for further information:
https://levelnis.co.uk/blog/configure-mvc-website-in-iis
In a new project as frontend developer the team I joined is using ASP.NET MVC for the backend. I am running a mac, so this means I can only compile the C# sources on Windows to run the application locally.
I have a Win10 setup inside a VM using virtual box. The sources are on the host and shared to the guest via a samba share (On Z:\ in the guest) and a host-only network adapter. Goal is to reach the app then from the host using the IP of the Guest, i.e. https://192.168.56.102:44301/ (it`s a single page application written in angular)
In the guest I compile from the command line using msbuild and then I start the REST API and the "Web App" using iisexpress.exe: (because visual studio is way to slow in the guest)
commands to build & start:
msbuild Z:\TheApp.sln
:: shell #1
iisexpress.exe" /config:Z:\.vs\config\applicationhost.config /site:"AppName.Api"
:: shell #2
iisexpress.exe" /config:Z:\.vs\config\applicationhost.config /site:"AppName.Web"
In Web.config of the Solution AppName.Web I have the following option:
<add key="ApiEndpointBase" value="https://192.168.56.102:44302/" />
The REST API is listening on port 44302, the "web app" on port 44301
So when I enter https://192.168.56.102:44301/ I get the app served.
The problem:
For each page reload the web app (HomeController.cs) does an http request against the API, so this means it is internally communicating to https://192.168.56.102:44302/
// HomeController.cs
// this fails with an exception like "An error occurred while processing your request.":
private readonly HttpClient client = new HttpClient();
...
/// <returns>The index view.</returns>
public async Task<ActionResult> Index() {
var response = await clientclient.GetAsync("api/foo?someId=" + someId);
client.BaseAddress is https://192.168.56.102:44302/
So there are two apps running in the guest using iisexpress, and one of them does an http request against the other using the Address https://192.168.56.102:44302/.... - and this request times out, or fails somehow and I don't get why.
It works if:
<add key="ApiEndpointBase" value="https://localhost:44302/" />
I visit https://localhost:44301/ in a browser inside the guest
But I want to access it from a browser on the host. Would really appreciate if some asp.net devs may help me here :)
EDIT:
External requests are already working. Else I would not get the app served on the host. I also registered the URLs using netsh and windows firewall is disabled on the guest. So I think this is not a duplicate of IIS Express enable external request
I am following Azure's Mobile Quickstart Tutorial (Xamarin.Android) and I was able to have the Facebook Authentication and Push Notification running.
Now, I wanted to know how to have a local development environment or have the Mobile App Service (Nodejs) run on my local machine instead (not on Azure Cloud). And I followed this tutorial:
https://shellmonger.com/2016/04/01/30-days-of-zumo-v2-azure-mobile-apps-day-2-local-development/
However, things break just after I open the app. See screenshots below:
Error:
Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException: Cannot PUT /push/installations/cc69e3d2-5d18-4077-a23a-56a845a73698
Couple of notes:
- This app works as it should if I connect it to the remote app service on Azure Cloud.
- Yes, I have the app server (nodejs) cloned in my local machine - installed required modules, and is running as it should (screenshot)
// This is a base-level Azure Mobile App SDK.
var express = require('express'),
azureMobileApps = require('azure-mobile-apps');
// Set up a standard Express app
var app = express();
// If you are producing a combined Web + Mobile app, then you should handle
// anything like logging, registering middleware, etc. here
// Configuration of the Azure Mobile Apps can be done via an object, the
// environment or an auxiliary file. For more information, see
// http://azure.github.io/azure-mobile-apps-node/global.html#configuration
var mobileApp = azureMobileApps({
// Explicitly enable the Azure Mobile Apps home page
homePage: true,
// Explicitly enable swagger support. UI support is enabled by
// installing the swagger-ui npm module.
// swagger: true,
// App will use MS_SqliteFilename or MS_TableConnectionString to choose the SQLite or SQL data provider
data: {
dynamicSchema: true
}
});
// Import the files from the tables directory to configure the /tables endpoint
mobileApp.tables.import('./tables');
// Import the files from the api directory to configure the /api endpoint
mobileApp.api.import('./api');
// Initialize the database before listening for incoming requests
// The tables.initialize() method does the initialization asynchronously
// and returns a Promise.
mobileApp.tables.initialize()
.then(function () {
app.use(mobileApp); // Register the Azure Mobile Apps middleware
app.listen(process.env.PORT || 3000); // Listen for requests
});
- And also yes, I changed the mobile app client's needed ApplicationURL to the one I have running locally (screenshot)
...
const string applicationURL = #"http://192.168.1.221:3000";
const string localDbFilename = "newlocalstore.db";
protected override async void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Activity_To_Do);
CurrentPlatform.Init();
...
- Lastly, I have my IP address already white-listed on the firewall setting of the MS SQL Server. So it shouldn't be an issue since I was also able to fully up my local app service (nodejs).
What do you think causes the error?
When you run locally, you must provide ALL the connection strings required - including ones that are automatically generated for you in the cloud. In this case, you have not defined the Notification Hubs connection string in the local
environment.
Go to Kudu (https://yoursite.scm.azurewebsites.net) and look at the environment variables for connection strings. They are rather obvious when you look for them. Make sure you have all the connection strings defined as the same environment variables.
Is anyone else having a difficult time getting Twitters oAuth's callback URL to hit their localhost development environment.
Apparently it has been disabled recently. http://code.google.com/p/twitter-api/issues/detail?id=534#c1
Does anyone have a workaround. I don't really want to stop my development
Alternative 1.
Set up your .hosts (Windows) or etc/hosts file to point a live domain to your localhost IP. such as:
127.0.0.1 xyz.example
where xyz.example is your real domain.
Alternative 2.
Also, the article gives the tip to alternatively use a URL shortener service. Shorten your local URL and provide the result as callback.
Alternative 3.
Furthermore, it seems that it works to provide for example http://127.0.0.1:8080 as callback to Twitter, instead of http://localhost:8080.
I just had to do this last week. Apparently localhost doesn't work but 127.0.0.1 does Go figure.
This of course assumes that you are registering two apps with Twitter, one for your live www.mysite.example and another for 127.0.0.1.
Just put http://127.0.0.1:xxxx/ as the callback URL, where xxxx is the port for your framework
Yes, it was disabled because of the recent security issue that was found in OAuth. The only solution for now is to create two OAuth applications - one for production and one for development. In the development application you set your localhost callback URL instead of the live one.
Callback URL edited
http://localhost:8585/logintwitter.aspx
Convert to
http://127.0.0.1:8585/logintwitter.aspx
This is how i did it:
Registered Callback URL:
http://127.0.0.1/Callback.aspx
OAuthTokenResponse authorizationTokens =
OAuthUtility.GetRequestToken(ConfigSettings.getConsumerKey(),
ConfigSettings.getConsumerSecret(),
"http://127.0.0.1:1066/Twitter/Callback.aspx");
ConfigSettings:
public static class ConfigSettings
{
public static String getConsumerKey()
{
return System.Configuration.ConfigurationManager.AppSettings["ConsumerKey"].ToString();
}
public static String getConsumerSecret()
{
return System.Configuration.ConfigurationManager.AppSettings["ConsumerSecret"].ToString();
}
}
Web.config:
<appSettings>
<add key="ConsumerKey" value="xxxxxxxxxxxxxxxxxxxx"/>
<add key="ConsumerSecret" value="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"/>
</appSettings>
Make sure you set the property 'use dynamic ports' of you project to 'false' and enter a static port number instead. (I used 1066).
I hope this helps!
Use http://smackaho.st
What it does is a simple DNS association to 127.0.0.1 which allows you to bypass the filters on localhost or 127.0.0.1 :
smackaho.st. 28800 IN A 127.0.0.1
So if you click on the link, it will display you what you have on your local webserver (and if you don't have one, you'll get a 404). You can of course set it to any page/port you want :
http://smackaho.st:54878/twitter/callback
I was working with Twitter callback url on my localhost. If you are not sure how to create a virtual host ( this is important ) use Ampps. He is really cool and easy. In a few steps you have your own virtual host and then every url will work on it. For example:
download and install ampps
Add new domain. ( here you can set for example twitter.local) that means your virtual host will be http://twitter.local and it will work after step 3.
I am working on Win so go under to your host file -> C:\Windows\System32\Drivers\etc\hosts and add line: 127.0.0.1 twitter.local
Restart your Ampps and you can use your callback. You can specify any url, even if you are using some framework MVC or you have htaccess url rewrite.
Hope This Help!
Cheers.
Seems nowadays http://127.0.0.1 also stopped working.
A simple solution is to use http://localtest.me instead of http://localhost it is always pointing to 127.0.0.1 And you can even add any arbitrary subdomain to it, and it will still point to 127.0.0.1
See Website
When I develop locally, I always set up a locally hosted dev name that reflects the project I'm working on. I set this up in xampp through xampp\apache\conf\extra\httpd-vhosts.conf and then also in \Windows\System32\drivers\etc\hosts.
So if I am setting up a local dev site for example.com, I would set it up as example.dev in those two files.
Short Answer: Once this is set up properly, you can simply treat this url (http://example.dev) as if it were live (rather than local) as you set up your Twitter Application.
A similar answer was given here: https://dev.twitter.com/discussions/5749
Direct Quote (emphasis added):
You can provide any valid URL with a domain name we recognize on the
application details page. OAuth 1.0a requires you to send a
oauth_callback value on the request token step of the flow and we'll
accept a dynamic locahost-based callback on that step.
This worked like a charm for me. Hope this helps.
It can be done very conveniently with Fiddler:
Open menu Tools > HOSTS...
Insert a line like 127.0.0.1 your-production-domain.com, make sure that "Enable remapping of requests..." is checked. Don't forget to press Save.
If access to your real production server is needed, simply exit Fiddler or disable remapping.
Starting Fiddler again will turn on remapping (if it is checked).
A pleasant bonus is that you can specify a custom port, like this:
127.0.0.1:3000 your-production-domain.com (it would be impossible to achieve this via the hosts file). Also, instead of IP you can use any domain name (e.g., localhost).
This way, it is possible (but not necessary) to register your Twitter app only once (provided that you don't mind using the same keys for local development and production).
edit this function on TwitterAPIExchange.php at line #180
public function performRequest($return = true)
{
if (!is_bool($return))
{
throw new Exception('performRequest parameter must be true or false');
}
$header = array($this->buildAuthorizationHeader($this->oauth), 'Expect:');
$getfield = $this->getGetfield();
$postfields = $this->getPostfields();
$options = array(
CURLOPT_HTTPHEADER => $header,
CURLOPT_HEADER => false,
CURLOPT_URL => $this->url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false
);
if (!is_null($postfields))
{
$options[CURLOPT_POSTFIELDS] = $postfields;
}
else
{
if ($getfield !== '')
{
$options[CURLOPT_URL] .= $getfield;
}
}
$feed = curl_init();
curl_setopt_array($feed, $options);
$json = curl_exec($feed);
curl_close($feed);
if ($return) { return $json; }
}
I had the same challenge and I was not able to give localhost as a valid callback URL. So I created a simple domain to help us developers out:
https://tolocalhost.com
It will redirect any path to your localhost domain and port you need. Hope it can be of use to other developers.
set callbackurl in twitter app : 127.0.0.1:3000
and set WEBrick to bind on 127.0.0.1 instead of 0.0.0.0
command : rails s -b 127.0.0.1
Looks like Twitter now allows localhost alongside whatever you have in the Callback URL settings, so long as there is a value there.
I struggled with this and followed a dozen solutions, in the end all I had to do to work with any ssl apis on local host was:
Go download: cacert.pem file
In php.ini * un-comment and change:
curl.cainfo = "c:/wamp/bin/php/php5.5.12/cacert.pem"
You can find where your php.ini file is on your machine by running php --ini in your CLI
I placed my cacert.pem in the same directory as php.ini for ease.
These are the steps that worked for me to get Facebook working with a local application on my laptop:
goto apps.twitter.com
enter the name, app description and your site URL
Note: for localhost:8000, use 127.0.0.1:8000 since the former will not work
enter the callback URL matching your callback URL defined in TWITTER_REDIRECT_URI your application
Note: eg: http://127.0.0.1/login/twitter/callback (localhost will not work).
Important enter both the "privacy policy" and "terms of use" URLs if you wish to request the user's email address
check the agree to terms checkbox
click [Create Your Twitter Application]
switch to the [Keys and Access Tokens] tab at the top
copy the "Consumer Key (API Key)" and "Consumer Secret (API Secret)" to TWITTER_KEY and TWITTER_SECRET in your application
click the "Permissions" tab and set appropriately to "read only", "read and write" or "read, write and direct message" (use the least intrusive option needed for your application, for just and OAuth login "read only" is sufficient
Under "Additional Permissions" check the "request email addresses from users" checkbox if you wish for the user's email address to be returned to the OAuth login data (in most cases check yes)