Showing posts with label WebMatrix. Show all posts
Showing posts with label WebMatrix. Show all posts

Monday, May 06, 2013

Webmatrix 3: Hold Off

I found a bug with Webmatrix 3 that may only happen to specific machine setups, which is this

http://stackoverflow.com/questions/16392844/webmatrix-3-sql-server-ce-4-busted


Not saying this will happen to you, I've read a bit and apparently most people claim everything is working great for them with Webmatrix 3.  But to be honest unless you are doing a lot with Azure or non razor development I would HOLD OFF installation of Webmatrix 3 just in case.

More info here http://forums.asp.net/t/1903867.aspx/1?WebMatrix+3+SQL+Server+CE+Database+Read+Only+ID+Column+Cannot+be+Modified


Tuesday, January 25, 2011

Basic Polling Web jQuery Chat Example Using WebMatrix

*** Update: I had a bunch of junk comments left over from testing in the sdf database, some were kind of crude. I removed them from the source. Numbers 32:23 in action :) ***

Ok, here is a VERY rudimentary example to help you get web chat functionality going in a webmatrix site. I'm not getting fancy at all here, just three pages and a SQL CE database -> Chatpage.cshtml, pull.cshtml, push.cshtml. Essentially I've got my chat page that uses jQuery to poll a "pull" page every 1.5 seconds. I keep track of what data to return by using session time variables. And there is a simple jQuery post method to post new chat messages.

Note! This is just meant to help get you going, not meant to be production code (no SQL injection defense, might need to watch out for Chars in Javascript that might throw things off, not styled at all, yadda yadda yadda). But there is enough here to get you going. Also be warned that you need to test this with two different types of browsers if you are testing the code on your local machine (else a same browser just different windows will share the same session and messages will start disappearing).

Here is the [Source Code]. Or you can look at each page's source individually (scroll bars at the bottom of the code if it over flows).

Here is the ChatPage.cshtml


Here is the Push.cshtml page source


Here is the Pull.cshtml page source

Here is a picture of the database schema

Monday, September 06, 2010

Stored Procedures and Webmatrix

OK, there isn't a whole lot of documentation for using stored procedures with Microsoft.Data in WebMatrix. Here is one way I got one to work, I'm hoping there is a better way.

Example of a post back insert using a stored proc. Note I'm not doing any validation here, and if you use this method do a little research on SQL Injection and guard against it.



@if (IsPost) {

var LinkName = Request["LinkName"];
var LinkURL = Request["LinkURL"];

string sQ = String.Format("execute dbo.myprocname @LinkName=\"{0}\",
@LinkURL=\"{1}",LinkName, LinkURL);

db.Execute(sQ);
}

Thursday, August 26, 2010

Using Twitter's @anywhere Service on Localhost (and with Web Matrix/IIS Express)

Here is the trick to get Twitter's @anywhere service (http://dev.twitter.com/anywhere) working on your localhost website for development and testing.

1) Don't put a call back url when you register your app.
2) On the link below where you register the call back url for your app, click the add domain link.
3) Add either localhost, 127.0.0.1, or both (may not take 127.0.0.1)
4) In your javascript specify the callback url (localhost, 127.0.0.0/auth.cshtml, whatever. I didn't test this but I think you might even be able to enter ports in (localhost:8080). I ended up setting my web server to run on port 80 (default) so I didn't need to add any ports. If you can't enter ports, you might be stuck having to run your dev web server on port 80 or 8080.

Done. No editing hosts files, nada. Why is this so easy and not documented? I think it is because of a recent change on Twitter's end to loosen things up a bit so you can test your applications. For deployment, you may need to actually enter a call back url for your application. I don't thinks so, but test.

For me I'm working with Web Matrix, and I wanted iis express to run on Port 80. Three things.

1) Turn off/stop your default non-IIS Express web server (apache, dev version of IIS full) so you don't get any conflicts.
2) navigate to where the web matrix exe file is located by opening up a console by typing cmd in the start run menu, then navigate to the path by typing something like cd: c:\mypath\. Once there you can run iis express from the command line (only way right now to specify a port).

type something like iisexpress /path:c\mywebpath\mywebsite\ /port:80

3) Right now you can't have any spaces in the path name. I figure that will be fixed in the next beta or the final release.

Wednesday, August 25, 2010

WebMatrix RendorPage() and Functions: Not Quite Include Files

Out of curiosity, I added a function to a header.cshtml file like so-

@functions {
   int AddTEST(int a, int b)
   {
      return a + b;
   }
}


Then I tried calling the function in index.cshtml like so-

@AddTEST(1,2);

As I thought, if failed. So, just to keep in mind all you scripters that RenderPage() in WebMatrix is not quiet like include files in PHP or Classic ASP. For functionality that is shared across pages you will need to create a class for that, which is pretty easy to do, but not quiet what you might be used to. Welcome to OOP :)

Sunday, August 22, 2010

Webrazor Newbie Tip: Getting a Record Count

OK, a common task is getting record counts. With WebMatrix, you return a query that actually is a bunch of objects that are IEnumerable. If you are a noob don't worry to much about what they means so much as what it allows you to do.

WebMatrix queries support the new .Net Linq functionality. This allows you to apply Linq operators to your query results which makes it easy to get record counts. Example:

@{
var db = Database.OpenFile("somedb.sdf");
var q1 = "select * from table";


}

There are a total number of @q1.Count() records in table.




Easy.

Using Gmail with Webmatrix ASP.Net Web Pages

OK, here is a basic example of how to use Gmail with Razor/WebMatrix ASP.Net web pages, in this case a .cshtml page.

  1. @{  
  2. try {  
  3.         // Initialize Mail helper  
  4.         Mail.SmtpServer = "smtp.gmail.com";  
  5.         Mail.SmtpPort = 587; //25 465; - 25 default, 465 in documentation, 587 works  
  6.         Mail.EnableSsl = true;  
  7.         Mail.UserName = "your user name"; // include domain if not gmail user@mydomain.com  
  8.         Mail.From = "return email address";   
  9.         Mail.Password = "your password";  
  10.            
  11.         // Send email  
  12.         Mail.Send(to: "target email",   
  13.             subject: "test",  
  14.             body:"yo!"  
  15.         );  
  16.     }  
  17.     catch (Exception ex ) {  
  18.         <text>  
  19.           <b>The email was <em>not</em> sent.</b>  
  20.           The code on the PrcessRequest page must provide the   
  21.           STMP server, user name, password, and email addresses   
  22.           required.  
  23.         </text>  
  24.     }  
  25. }  

Monday, August 09, 2010

Coding Snobs and WebMatrix

I've had a feeling for a while now that programming is becoming to nerd dominated and fad driven. If you do a Google search on Microsoft.data.dll, it will be eye opening just how opinionated these little geeks can be. But if you dig past all their little fo arguments about best practices, the craft of software development, how webmatrix is a step backwards, etc... you begin to reveal that the primary motivator for the geek squad is that tools like the WebMatrix might make Web Development easier, which threatens the geek's elitist geek only club.

I started in Web Development with classic ASP. All the critiques of classic ASP and for that matter PHP leveled by the geek elite are generally accurate (spaghetti code, no separation of concerns, no OOP, hard to test, violating the DRY principle, etc...). But to me at least, it sure seems like I got more web applications out the door back then. Half the time now I'm struggling to keep up with technology rather than solving client problems.

Case in point. I work with an extremely talented developer. He took a stab at Silverlight. It took him about a month to get some even basic concepts like taking data from a user's input and saving it to the database. I was in a similar situation with Silverlight 3 awhile back, where I was using it but decided to stop when I started running into problems doing what I would think are simple things. The datasave models I think are way to complicated. The geeks will stay up 14 hours a day coding to figure things out. I'm fine with that, if IT IS NECESSARY. But I really don't think the pain is necessary, not if Silverlight was being designed for Morts rather than Einsteins and Elvisis (using Microsoft's terminology to describe developers). I don't mind have to stretch and learn new things to get problems solved, but doing basic stuff like data connectivity shouldn't be as hard as it seems to be sometimes, and I think the issues arise because Microsoft for so long has been driven by the elite geek crowd. This is a small crowd, and if Microsoft continues to only target tools at this crowd, Microsoft will go the way of Novell and Lotus Notes.

That being said, I think webmatrix was a great step by Microsoft, unfortunately it is a step that should have been made around 2003. Not only does webmatrix have to lure PHP developers, but it also has to lure people away from Mac's to PC's. That is a tough sell to the growing Mac hipster crowd, and uphill battle. But I give Microsoft props for trying.