I've put together a very basic tutorial for a jQuery Mobile app with a very basic tutorial using the Web Api with VS 2013 and VB.NET. The Web Api is just for use with my UI within my app as a way to bridge between html and asp.net. It works perfectly on my development machine but the Web Api part fails when I move it to my hosting service (WinHost). I assume that there is a web.config entry that will fix this - but, I'm totally lost on this point. The html/jQuery code is:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" href="css/custom.css" />
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery-mobile/1.3.2/jquery.mobile.min.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css" />
<title>Boilerplate</title>
<script>
var uri = 'api/class1s';
function formatItem(item) {
return item.field1;
}
function find() {
var id = $('#prodId').val();
$.getJSON(uri + '/' + id)
.done(function (data) {
$('#product').text(formatItem(data));
})
.fail(function (jqXHR, textStatus, err) {
$('#product').text('Error: ' + err);
});
}
</script>
</head>
<body>
<div data-role="page">
<div data-role="header">
<h1>Boilerplate</h1>
</div>
<div data-role="content">
<p>Page Body content</p>
<div>
<input type="text" id="prodId" size="5" />
<input type="button" value="Search" onclick="find();" />
<p id="product" />
</div>
</div>
<div data-role="footer">
<h4>Footer content</h4>
</div>
View Full Site
</div>
</body>
</html>
The web.config is:
<configuration>
<appSettings></appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5.1" />
<httpRuntime targetFramework="4.5.1" />
</system.web>
<system.webServer>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*"
type="System.Web.Handlers.TransferRequestHandler"
preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
</configuration>
There is also a WebApiConfig:
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web.Http
Public Module WebApiConfig
Public Sub Register(ByVal config As HttpConfiguration)
' Web API configuration and services
' Web API routes
config.MapHttpAttributeRoutes()
config.Routes.MapHttpRoute(
name:="DefaultApi",
routeTemplate:="api/{controller}/{id}",
defaults:=New With {.id = RouteParameter.Optional}
)
End Sub
End Module
There is also a class to define the data and a controller to populate data and return data via the Web Api.
These should not affect this problem (and work perfectly on my desktop PC).
Otherwise, this is just a standard VS2013 ASP.Net 4.5.1 project using an empty website with the Web Api option selected.
Is there a way to get this program to work on the hosting service?
Related
My question is about Asp.Net website hosting on shared server. I have a website which has 1 master page and 4000 child pages, website is made in asp.net but pages are like static - I am not using any database in it. I simple create a child page from the master page, write the Title, Heading, Description & content. Website has 30,000 to 40,000 pageviews per day.
The issue is that: When I make any change in the master page, website went down for 3-4 hours. No issue with child page uploading - to upload the pages I use FileZilla(any number of child page can be uploaded and no Issue of website down).
I am using GoDaddy's Ultimate Windows Hosting plan
Here is my Master page code:
<%# Master Language="VB" AutoEventWireup="true" CodeFile="mpageR.master.vb" Inherits="mywebsite" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link rel="stylesheet" href="css/W3.css"/>
<link rel="stylesheet" href="css/style1.css"/>
<!-- START: Analytics-->
<!-- Analytics code-->
<script type="text/javascript">
...
</script>
<!-- END: Analytics Code-->
<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<!--Main Page Section-->
<form id="form1" runat="server">
<div class="w3-row">
<!--Header control (reading a file in this control to show header section)-->
<%# Register TagPrefix="uc" TagName="header_cntrl" Src="~/user-controls/header.ascx" %>
<uc:header_cntrl id="header_cntrl1" runat="server"/>
<!--End of Header-->
</div>
<div class="w3-row">
<!--main section-->
<div class="left-panel">
<!-- Left Nav Menu (reading file for left panel)-->
<%# Register TagPrefix="uc" TagName="LeftNavMenu" Src="~/plugins/LeftNavMenu.ascx" %>
<uc:LeftNavMenu id="LeftNavMenu" runat="server"/>
<!-- End of Left Nav Menu-->
</div>
<div class="main-panel">
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
<div class="right-panel">
<!-- Right Nav Menu (reading file for right section)-->
<%# Register TagPrefix="uc" TagName="RgtNavMenu" Src="~/plugins/RgtNavMenu.ascx" %>
<uc:RgtNavMenu id="RgtNavMenu" runat="server"/>
<!-- End of Right Nav Menu-->
</div>
</div>
<br />
<!--Footer control (reading file for footer)-->
<%# Register TagPrefix="uc" TagName="footer_cntrl" Src="~/user-controls/footer.ascx" %>
<uc:footer_cntrl id="footer_master" runat="server"/>
<!--End of Footer-->
</form>
<!--End of Main Page Section-->
</body>
</html>
Web.config file:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0">
</compilation>
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
<customErrors mode="On">
<error redirect="~/error.aspx" statusCode="404"/>
</customErrors>
</system.web>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect to WWW" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^mywebsiye.com$" />
</conditions>
<action type="Redirect" url="https://www.mywebsite.com/{R:0}"
redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
I have created a SignalR server, a web client, and a mobile application built with PhoneGap Build. When I launch the PhoneGap application with lite-server, PhoneGap CLI, or the PhoneGap Desktop Application the SignalR works flawlessly between the web client and the PhoneGap application. This includes using the PhoneGap mobile application to connect to the PhoneGap Desktop application. The only time it fails is when I build it with PhoneGap Build and install the APK on the device. I have no explanation for this error.
I have handled CORS through the WEB.CONFIG of the server. It is a plain ASP.NET application that just has an OWIN startup file to configure SignalR and a Hub class.
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Methods" value="GET, POST, OPTIONS, PUT, DELETE, TOKEN" />
<add name="Access-Control-Allow-Credentials" value="false"/>
</customHeaders>
</httpProtocol>
</system.webServer>
The frustrating part is that the error that is produced when $.connection.hub.start fails is just "Error: Error during negotiation request"
When 'deviceready' event triggers I call initiateSignalR()
var appConfig = {
'serverUrl': "http://wolf-signalrserver.azurewebsites.net"
}
var initiateSignalR = function(){
if ($.signalR) {
}
var username = prompt("username");
var success = `
<div class ="serverMessage">
<span>--- WELCOME, ${username} ---</span>
</div>
`
$('#chatbox').append(success)
$.connection.hub.logging = true
$.connection.hub.qs = { 'username': username }
$.connection.hub.url = appConfig.serverUrl + "/signalr";
var chatHub = $.connection.chatHub
chatHub.client.broadcastMessage = function (name, message) {
console.log("Data Incoming ---- Name: " + name + " Message: " + message);
var message = `
<div class="row">
<span class="col-sm-2">${name}:</span>
<span class="col-sm-9"> ${message}</span>
</div>
`
$('#chatbox').append(message)
}
$('#messageButton').on('click', function () {
chatHub.server.send(username, $('#messageBox').val())
})
$('#messageForm').on('submit', function (e) {
e.preventDefault();
chatHub.server.send(username, $('#messageBox').val())
})
$.connection.hub.start({ withCredentials: false, jsonp: true })
.done(function () {
console.log("Connected successfully to SignalR");
var success = `
<div class ="serverMessage">
<span>--- Successfully connected to the server ---</span>
</div>
`
$('#chatbox').append(success)
})
.fail(function (err) {
console.log("Unable to connect to SignalR")
alert(err);
})
}
I have a git repo of this here: https://github.com/PhilWolf91/SignalR
I realize there are tons of questions here with this, but none of them have a detailed answer to how they fixed it.
Ex: SignalR .Net Client fails with 500 server error on device, on simulator works fine
OK. I'm a giant idiot. When I was cleaning up the Config.Xml I removed the network permission AND the default White List plugin.
<feature name="http://api.phonegap.com/1.0/network" />
<gap:plugin name="cordova-plugin-whitelist" source="npm" />
Full functional config for this project
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.wolf.signalrphonegap" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0">
<name>SignalRPhoneGap</name>
<description>
Hello World sample application that responds to the deviceready event.
</description>
<author email="phillip.wolf91#gmail.com" href="http://phillipwolf91.wordpress.com">
Wolf Software
</author>
<feature name="http://api.phonegap.com/1.0/network" />
<gap:plugin name="cordova-plugin-whitelist" source="npm" />
<content src="index.html" />
<preference name="DisallowOverscroll" value="true" />
<preference name="android-minSdkVersion" value="14" />
<platform name="android">
</platform>
<access origin="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<platform name="android">
<allow-intent href="market:*" />
</platform>
</widget>
I now have SignalR working between the Server, Web Client, and PhoneGap app installed on the device
When I go to the root of my ASP.NET website, the request goes into the ASP.NET pipeline and then returns index.html.
Is there a way in web.config to configure this so that IIS simply returns the file without going into the ASP.NET pipeline?
index.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Test</title>
</head>
<body>
<h1>Test</h1>
</body>
</html>
Global.asax:
using System.Web;
namespace Test
{
public class Global : HttpApplication
{
protected void Application_BeginRequest()
{
var url = this.Request.Url;
}
}
}
web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
</configuration>
You can set runAllManagedModulesForAllRequests=false inside web.config. It has other side effects, but can give a try first.
<system.webServer>
<modules runAllManagedModulesForAllRequests="false" />
</system.webServer>
I am tring to utilize a simple SignalR sample and from a reason I get the 404 code from the following -
<script src="<%= ResolveUrl("~/signalr/hubs") %>" type="text/javascript"></script>
I checked the SignalR documentation and changed my web.config according to what is suggests there still I get that 404 status code.
my code follows -
Web.Config:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</assemblies>
</compilation>
<httpRuntime/>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true">
</modules>
</system.webServer>
</configuration>
Default.aspx:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="Scripts/jquery-1.6.4.min.js" type="text/javascript"></script>
<script src="Scripts/jquery.signalR-0.5.3.min.js" type="text/javascript"></script>
<script src="<%= ResolveUrl("~/signalr/hubs") %>" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
//var connection = new Connection( "127.0.0.1");
// Proxy created on the fly
var chat = $.connection.chatt;
// Declare a function on the chat hub so the server can invoke it
chat.addMessage = function (message) {
$('#messages').append('<li>' + message + '</li>');
};
$("#broadcast").click(function () {
// Call the chat method on the server
chat.send($('#msg').val());
});
// Start the connection
$.connection.hub.start();
});
</script>
</head>
<input type="text" id="msg" />
<input type="button" id="broadcast" value="broadcast" />
<ul id="messages">
</ul>
</html>
Please assist.
I had this same problem, the solution is putting this in your Global.asax file:
protected void Application_Start(object sender, EventArgs e)
{
RouteTable.Routes.MapHubs();
}
Unfortunately this isn't documented anywhere, even though it's an essential part of SignalR configuration...
HttpModule class as follows:-
namespace WebApplication1
{
public class RewriterHttpModule : IHttpModule
{
public void Init(HttpApplication r_objApplication)
{
// Register our event handler with Application object.
r_objApplication.BeginRequest += new EventHandler(BeginRequest);
}
public void Dispose()
{
// Left blank because we dont have to do anything.
}
protected void BeginRequest(object r_objSender,
EventArgs r_objEventArgs)
{
// Authenticate user credentials, and find out user roles.
HttpApplication objApp = (HttpApplication)r_objSender;
HttpContext objContext = (HttpContext)objApp.Context;
string fullOrigionalpath = objContext.Request.Url.ToString();
if (fullOrigionalpath.Contains("/Default/Books.aspx"))
{
objContext.RewritePath("/Default.aspx?Category=Books");
}
else if (fullOrigionalpath.Contains("/Default/DVDs.aspx"))
{
objContext.RewritePath("/Default.aspx?Category=DVDs");
}
}
}
}
Web.Config file as follows:-
<configSections>
<section name="rewriter" requirePermission="false"
type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter" />
</configSections>
<add name="UrlRewriter" type="WebApplication1.RewriterHttpModule, WebApplication1"/>
</httpModules>
<rewriter>
<rewrite url="~/Default/books.aspx" to="~/Default.aspx?category=books"/>
<rewrite url="~/Default/CDs.aspx" to="~/Default.aspx?category=CDs" />
<rewrite url="~/Default/DVDs.aspx" to="~/Default.aspx?category=DVDs" />
</rewriter>
Sitemaster Page as follows:-
<head runat="server">
<title></title>
<link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
<asp:ContentPlaceHolder ID="HeadContent" runat="server">
</asp:ContentPlaceHolder>
</head>
I have the url rewriting working alright but when the default.aspx page is loaded on the browser it is not styled by the css stylesheet. What could be the problem?
Check this link:
IIS Rewrite
And for css/javascript you must use absolute path, like:
<script src="../my.js"/><script>
will become
<script src="/js/my.js"/><script>
Something like that.
Forgot to explain.
Suppose in original link /default.aspx?Category=books
you have
When browser load the page it will look after /mystyle.css
When you put /default/books.aspx (that it will load default.aspx?Category=books)
the browser will look after /default/mystyle.css (but you do not have the default directory and mystyle.css in this directory).
Do nothing when requesting script folder like:
<if url="^/css/(.+)$">
<rewrite to="~/$1" processing="stop" />
</if>
or just add this to top of rewrite config
<rewrite url="^(/.+(\.gif|\.flv|\.swf|\.png|\.jpg|\.ico|\.pdf|\.doc|\.xls|\.css|\.zip|\.rar|\.js|\.xml|\.mp3)(\?.+)?)$" to="$1" processing="stop" />
i think your css path will be changed. have you checked by viewsource?
any way, applied the css in that way:
<link href='css/homepage.css' rel='stylesheet' type='text/css' />
hope this help.