I'm trying to build a simple Web Service application in ASP.NET C# and make a call from another project written in PHP. The problem when I make an AJAX call I get this error:
POST http://localhost:49566/WebApplication2/ReviewService.asmx/getReviewById net::ERR_CONNECTION_REFUSED
I have added "Access-Control-Allow-Origin" in my Web.config:
<configuration>
<connectionStrings>
<add name="localDatabase" connectionString="Server=localhost;Database=mydb;Uid=root;Pwd=gameover;" />
</connectionStrings>
<system.web>
<authorization>
<allow users="*"/>
</authorization>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
</customHeaders>
</httpProtocol>
</system.webServer>
This is my $.ajax call from PHP:
$( document ).ready(function() {
$.ajax( {
method:'post',
data: {user_id: 1},
url:'http://localhost:49566/WebApplication2/ReviewService.asmx/getReviewById',
success:function(data) {
alert(data);
}
})
});
I really don't know what is the problem here. Thanks for your help
I've had similar problems when running in Visual Studio debugger (VS2013). In debugger everything worked great (when running inside VS), but when I stopped debugger, site was no longer available.As it turned out, it was setting "Edit and continue" which was enabled on ASP.NET project, which is enabled by default. Turning this setting off made my site (or webservice) available on localhost even when I stopped debugger. I also got ERR_CONNECTION_REFUSED when trying to browse to a site, before turning this setting off. That means you are not able to correct code while debugging, but that was ok for me.
Related
I've got an MVC webpage with Windows authentication where users log in using domain credentials. Here are my auth web.config settings:
<system.web>
<compilation debug="true" targetFramework="4.6.1" />
<httpRuntime targetFramework="4.5" maxQueryStringLength="32768" maxUrlLength="65536" />
<customErrors mode="Off" />
<authentication mode="Windows" />
<authorization>
<allow roles="NG\All-Trained-Users" />
<deny users="*" />
</authorization>
<hostingEnvironment shadowCopyBinAssemblies="false" />
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Optimization" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
</namespaces>
</pages>
<identity impersonate="true" />
</system.web>
However, access to shared resources is denied in the app.
Users are prompted for Windows auth after the global.asax.cs Application_Start() method finishes. In that method, the app has access to shared resources. For example, Console.Writeline(Directory.Exists("\\existing\shared\directory")) prints "true". My understanding is the logged-in Windows user identity is being used to authenticate access -- right?
I'm using the same credentials to log into Windows and to log into the webpage. However, when I log into the webpage, something changes, because Console.Writeline(Directory.Exists("\\existing\shared\directory")) prints "false" as the first line of the Index() method. Trying to access a file returns a System.UnauthorizedAccessException . Are those credentials treated differently within MVC?
System.Environment.UserName and System.Environment.UserDomainName return the same values in both Application_Start() and Index(). In File Explorer this user can navigate to the shared location and access files just fine. The network location lists the user as having access.
I've run out of places I know to look to fix this problem. I'm sure if I look in the right place it will show the wrong user or wrong domain or wrong authentication method, but I don't know where to look. Any hints for where I should go?
I'm going to blame the pandemic for this one. Evidently, when our office moved to remote and began using the VPN, our VPN settings triggered additional security features in IIS Express:
When using Integrated Security, anonymous access is disabled, and impersonation is turned on, a security measure kicks in and doesn't allow your site to access resources on any network servers.
We could probably track down a more secure fix to the VPN settings, but our temporary solution while out of office is to not use impersonation while debugging over the VPN.
I'm setting up a new app on a server on my work and when I access to the ip address on the explorer shows the default app
Default app
but when I try to access to the app that i created shows this error
My app
This is my web.config file
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.webServer>
<defaultDocument>
<files>
<clear />
<add value="Default.aspx" />
</files>
</defaultDocument>
</system.webServer>
<system.web>
<compilation targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" />
<pages>
<controls>
<add tagPrefix="ajaxToolkit" assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" />
</controls>
</pages>
</system.web>
<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
</appSettings>
</configuration>
This are my files
Files of application
I tried a lot of solutions, like permitions on folders on the IIS manager, enabling anonymous access, modifying web.config file, modifying the AutoEventWireup="true|false " etc but all of them leads me to the same error, can it be a compilation error? I am publishing via file system and pasted it on the wwwroot directory
Also I am using master pages except for the first page (the login)
With the configuration you are showing you most likely need to configure a virtual directory in IIS for your application to run in.
I solved my problem (not sure what I did diferent than before but its working now)
Instead of adding another website I added an application on the default website
and that solved the problem
Thanks a lot
I have an issue regarding my Web API. This API calls an external API to return addresses using postcode.
So basically it works on the server it is hosted. Please take note that this is a folder converted into an application in IIS 8.5, AppPool is Integrated, Version is 4.0. On some cases it works but after 10 or 20 minutes it returns 404. It does not have a problem if I access it on the server itself only outside the network. It will work sometime but after a few minutes, 10 or 20 it wont and will return 404 then vice-versa. Does this have anything to do with Network? I'm not in-charge of it so I'm asking.
I call it using link format below:
https://example.com/ConvertedToAppFolder/FindAddress/webservice.asmx/GetAddress?postcodeval=xxxxxxx&houseno=xx
Here is my web.config file
<?xml version="1.0"?>
<configuration>
<system.web>
<customErrors mode="Off"/>
<compilation debug="true" targetFramework="4.0"/>
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
</system.web>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>
Any help is very much appreciated.
Likely it's not code problem, but API server. Try to create new pure project and access to this API, if it works fine then i wrong and it's code issue. May be it has limited access, like google translater api allow only 1,000,000 letters per day and 10,000,000 per day.
I have developed a simple ASP.Net MVC 4 application using Windows Authentication to run on our company's local network. It works fine when deployed on IIS. But if I run the application through Visual studio, I get error message
Here is how my Web.Config file looks like
<system.web>
<authentication mode="Windows" />
<roleManager defaultProvider="WindowsProvider" enabled="true" cacheRolesInCookie="false">
<providers>
<add name="WindowsProvider" type="System.Web.Security.WindowsTokenRoleProvider" />
</providers>
</roleManager>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime maxUrlLength="32767" maxQueryStringLength="32767" targetFramework="4.5" />
</system.web>
<system.webServer>
<modules>
<!--<remove name="FormsAuthenticationModule" />-->
</modules>
<security>
<requestFiltering>
<requestLimits maxUrl="32767" maxQueryString="32767" />
</requestFiltering>
</security>
For debugging, Application is configured to run using "Local IIS Web Server" with "Use IIS Express" option checked in Applications's Properties ->Web tab.
It turns out to be that I had to Enable Windows Authentication, Disable Anonymous Authentication in the Development Server Properties of my Project.
You need to add to project Web.config this:
<system.web>
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" timeout="1" />
</authentication>
</system.web>
Where /Account/Login is your login method from controller.
Make sure your Directory Browsing is enabled.
See this link for adding user in IIS.
I am using an HttpModule to do some URL shortening on my site. I am using Visual Studio 2008 and IIS 7, and .Net 3.5.
When the module is specified in the system.webServer element of web.config, and the site is run in IIS, it works fine. The config looks like this:
<system.webServer>
<modules>
<add name="MinimizeModule" type="ClipperHouse.UrlMinimizer.MinimizeModule" />
</modules>...
My module attaches to the BeginRequest event, everything works. However, I can't get it to run using the built-in VS web server (Cassini). I tried moving the module config to the system.web element in web.config, no luck. I put a breakpoint on it, nothing happens.
Any thoughts on why this would be an issue?
(I also tried the Application_BeginRequest event in global.asax. Still no luck, though I'd prefer to keep everything in web.config anyway.)
Cassini, the development web server provided with IIS uses the IIS6 module syntax, so you must duplicate the module add like so
<system.web>
<httpModules>
<add name="MinimizeModule" type="ClipperHouse.UrlMinimizer.MinimizeModule" />
</httpModules>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules>
<remove name="MinimizeModule" />
<add name="MinimizeModule" type="ClipperHouse.UrlMinimizer.MinimizeModule"
preCondition="managedHandler" />
</modules>
</system.webServer>
Note that I've also added a precondition to your IIS7 settings
If you are running on IIS 7, put the module in:
<configuration>
<system.webServer>
<modules>
<add name="MinimizeModule" type="ClipperHouse.UrlMinimizer.MinimizeModule" />
</modules>
</system.webServer>
</configuration>
If you are running on Cassini (Visual Studio's integrated miniature web-server), put the module in:
<configuration>
<system.web>
<httpModules>
<add name="MinimizeModule" type="ClipperHouse.UrlMinimizer.MinimizeModule" />
</system.web>
</configuration>
IIS will crash if you give it the Cassini location.
Cassini will crash if you give it the IIS location.
Whenever i deploy, i have to be sure not to deploy web.config. i also include the notes in web.config:
<system.web>
<!--The Cassini location to add modules (comment out for IIS)-->
<httpModules>
<!--WARNING: IIS will crash if you leave this in here.
IISBUG: IIS doesn't support system.web/httpModules,
and Cassini doesn't support system.webServer/modules
-->
<!--Comment out for IIS-->
<add name="PerformanceHttpModule" type="DummyPlaceholder.PerformanceHttpModule"/>
</httpModules>
</system.web>
<system.webServer>
<!--The IIS7 location to add modules (comment out for Cassini)
<modules runAllManagedModulesForAllRequests="true">
<!--IIS7 will crash if you present a system.web httpModules. -->
<remove name="PerformanceHttpModule" />
<add name="PerformanceHttpModule" type="DummyPlaceholder.PerformanceHttpModule"/>
</modules>
</system.webServer>
IIS's left hand doesn't know what Cassini's right hand is doing - and they both screwed it up.
Did you try also putting the module declaration in the element? When running in dev using Cassini, that's usually the place I have to put modules to get them running.