Mar 24, 2014

Overview of ASP.NET configuration, security etc on Microsoft support

http://support.microsoft.com/kb/307626

Unauthorized access - Can't browse ASP.NET application with IIS 8.5 on Windows 8.1

I've setup security for ASP.NET site as usual - IIS_IUSRS on folder etc.
I could get ASPX but CSS and images no - unathorized.

Make sure to give your  "Users (MACHINE\Users)" group rights on web application folder.

Mar 17, 2014

ASP.NET WebForms - Client Report Definition - dynamically generate PDF presentation of RDLC from code

using Microsoft.Reporting.WebForms;

....


LocalReport localReport = new LocalReport();

            localReport.ReportPath = @"c:\Users\sbencetic\Documents\Visual Studio 2012\Projects\WebApplication2\Report1.rdlc";
            //ReportDataSource reportDataSource = new ReportDataSource("Customers", Customers.GetAllCustomers());

            //localReport.DataSources.Add(reportDataSource);
            string reportType = "Excel";
            string mimeType;
            string encoding;
            string fileNameExtension;

            //The DeviceInfo settings should be changed based on the reportType
            //http://msdn2.microsoft.com/en-us/library/ms155397.aspx
            string deviceInfo =
            "<DeviceInfo>" +
            "  <OutputFormat>PDF</OutputFormat>" +
            "  <PageWidth>8.5in</PageWidth>" +
            "  <PageHeight>11in</PageHeight>" +
            "  <MarginTop>0.5in</MarginTop>" +
            "  <MarginLeft>1in</MarginLeft>" +
            "  <MarginRight>1in</MarginRight>" +
            "  <MarginBottom>0.5in</MarginBottom>" +
            "</DeviceInfo>";

           
            Warning[] warnings;
            string[] streams;
            byte[] renderedBytes;

            //Render the report
           
            renderedBytes = localReport.Render(
                reportType,
                deviceInfo,
                out mimeType,
                out encoding,
                out fileNameExtension,
                out streams,
                out warnings);
            Response.AddHeader("content-disposition", "attachment; filename=NorthWindCustomers." + fileNameExtension);
           
            Page.Response.BinaryWrite(renderedBytes);                      


JQuery training

http://try.jquery.com/

Windows desktop - where is my appsettings in app.config ?

After long time working with web I got frustrated with trivial thing.
You can not open App.Config and simply write down your appsettings.
In windows desktop trick is to go through project properties then select Setting and use VS editor.

Mar 6, 2014

Windows 8.1 - can't save file to c:\Windows

Microsoft has increased out of the box security of Windows 8.1

By default user even as local admin does not have Full Control on some system folders like c:\Windows.

You can google solution like this:

http://www.thewindowsclub.com/take-ownership-windows-8

Yet this didn't gave me all answers.

Follow these steps:

1. On folder you wish right click
2. Select Security
3. Select Advanced
4. On the top change owner to yourself:     domain\username
5. Apply
6. Repeat step 1.
7. Edit
8. Locate yourself in user list and give Full control

Feb 27, 2014

SQL Compact Edition tips & tricks (ADO.NET)

Support for SQL Compact Edition is ... well sparse. It's one of those unwanted child's of Microsoft that he tries quickly to forget.
That means you'l have pain if you choose that way.
Just few years ago making local database in VS 2008 was child's game. Everything was there, project Data template, designer.
Now in VS 2013 it's hell.
At the moment if you need some kind of local database you can use "Service-based database" VS template.
It uses MDF & LDF files architecture from SQL server. I'm not clear how can you distribute this database to application users. There is some talk about special licence concerning use of this type of database.
Another approach is to dive into SQL CE fog.

1. Using Extensions & Updates, find and install third-party SQL Compact Toolbox.
Careful people say it's full of bugs and not well maintained.

2. Install NuGet package "Microsoft SQL Server Compact Edition"

3. Using SQL Compact Toolbox create new local SDF file.

4. Create connection string:

<add name="Application" connectionString="Data Source=|DataDirectory|\SQLCEv2.sdf;" providerName="System.Data.SqlServerCe.4.0"/>

For more info about DataDirectory folder substition read:

Folder substitution in DataSource property of Connection string:

http://social.msdn.microsoft.com/Forums/sqlserver/en-US/0712dd47-8437-4c84-b27e-2b12fddf2153/what-is-the-datadirectory-in-data-source-datadirectorynorthwindsdf?forum=sqlce


5. ADO.Net should work now:

string conStr = ConfigurationManager.ConnectionStrings["Application"].ToString();
            SqlCeConnection con = new SqlCeConnection(conStr);
            con.Open();
            SqlCeCommand cmd = new SqlCeCommand("insert into [Product] (Name) VALUES('Sinisa')", con);
            cmd.ExecuteNonQuery();
            con.Close();


Instead of ADO.NET you can use NPoco with no problem.