Thursday, October 9, 2014

Remote access to IIS Express

If you try to access the IIS Express website from a remote computer, you wont be able to do it unless you follow these steps.


Open C:\Users\[YourName]\Documents\IISExpress\config\applicationhost.config 
Look for <sites> section
In there find your site

<site name="MyWeb" id="2">
    <application path="/" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="E:\MyWeb" />
        <binding protocol="http" bindingInformation="*:52891:localhost" />
        <binding protocol="http" bindingInformation="*:8080:" />

Now, create another binding as highlighted. IP address is your computers' IP, port is whatever the port you want.

Allow incoming connections: Open command prompt as admin
netsh http add urlacl url= user=everyone
Open firewall:
netsh advfirewall firewall add rule name="IISExpressWeb" dir=in protocol=tcp localport=8080 profile=private remoteip=localsubnet action=allow

Tuesday, October 7, 2014

Web API 2 - Route Not Found (404)

It worked before, now it doesn't?

Here's the checklist.

  • Web API routes registration.

    protected void Application_Start()

Web API config should come before normal Routes.

  • Route Prefix
 change [Route("~/api/sendemail")] to [Route("/api/sendemail")]

Prefix "~" is not needed.

  • Route values
public bool SendEmail(int id, ContactModel data)
    return Ok();
notice the route defines a myId but method accepts an id. This will give a 404
Change the id or myId like this for it to work.

public bool SendEmail(int myId, ContactModel data){
    return Ok();