Search This Blog

Wednesday, February 5, 2014

Helpful ASP.NET forms authenication and session timeout article


From Adam Tuliper's Development Tips

What happens when user session timeouts before Form authenication does?

http://completedevelopment.blogspot.com/2009/12/caution-with-using-sessiontimeout-and.html

Modifield code from Adam's article:

Add the following code to global.asax to reroute request to login if session has expired:

protected void Application_PreRequestHandlerExecute(object sender, EventArgs e)
        {
            //Only access session state if it is available
            if (Context.Handler is IRequiresSessionState || Context.Handler is IReadOnlySessionState)
            {
                //If we are authenticated AND we dont have a session here.. redirect to login page.
                HttpCookie authenticationCookie = Request.Cookies[FormsAuthentication.FormsCookieName];
                if (authenticationCookie != null)
                {
                    FormsAuthenticationTicket authenticationTicket = FormsAuthentication.Decrypt(authenticationCookie.Value);
                    if (authenticationTicket != null && !authenticationTicket.Expired)
                    {
                        if (Session["username"] == null)
                        {
                            //This means for some reason the session expired before the authentication ticket. Force a login.
                            FormsAuthentication.SignOut();
                            Response.Redirect(FormsAuthentication.LoginUrl, true);
                            return;
                        }
                    }
                }
            }
        }

Wednesday, January 22, 2014

Freeware SMTP server software for Windows

Found a useful SMTP server in case the version of Windows you have does not include SMTP server features. I needed a quick to setup SMTP server for testing.

http://www.softstack.com/freesmtp.html


Setting up Windows SMTP server:

http://support.microsoft.com/kb/2600912/en-us

http://www.vsysad.com/2012/04/setup-and-configure-smtp-server-on-windows-server-2008-r2/

Friday, January 17, 2014

Opening Firewall for SQL Server allowing TCP access

From Microsoft TechNext

When you can't access a remote sql server, always change the firewall 1st.
the confirm what the sa / user password.

To open a port in the Windows firewall for TCP access

  1. On the Start menu, click Run, type WF.msc, and then click OK.
  2. In the Windows Firewall with Advanced Security, in the left pane, right-click Inbound Rules, and then click New Rule in the action pane.
  3. In the Rule Type dialog box, select Port, and then click Next.
  4. In the Protocol and Ports dialog box, select TCP. Select Specific local ports, and then type the port number of the instance of the Database Engine, such as 1433 for the default instance. Click Next.
  5. In the Action dialog box, select Allow the connection, and then click Next.
  6. In the Profile dialog box, select any profiles that describe the computer connection environment when you want to connect to the Database Engine, and then click Next.
  7. In the Name dialog box, type a name and description for this rule, and then click Finish.


Friday, December 27, 2013

How to get my iPad to connect to a local hosted site on an internal network

Last two years, I have been transforming from Windows flat client /database centered application developer (VB6, MS access, C#) to being a Microsoft centered web developer using MVC / ASP.net.

There are so many things to understand moving from Windows OS to Web platforms
 - Web server settings, application pools, protocol bindings, Firewalls
 - Understanding basic organization of ASP.NET projects
 - Making sense of javascript, client vs server side script execution
 - Browsers on various plaforms, Windows OS, andriod, iOS
 - Web site design geared to mobile devices
 - Learning tools like Fiddler

Add to this list, how can you get a mobile device like an iPad to access a web site hosted on a local network server.  Something that is essential when you trying to make UI changes for the iPad.

Here is an excellent article from WebEgg site: http://www.webegg.co.uk/local-web-sites-on-ipad-mobile/
Please take time to read through the article.  The solution to the problem is using proxyu settings to setup a reverse proxy allowing specifically configured devices to interact with you local server web site.

Steps:

Like magic, sites configured on localserver/IIS will be accessible on your iPad.

Next task, find the solution the nexus 7.
 Trying the same steps on the nexus 7 did not work. :(


Found a simpler solution:
http://www.mobitechie.com/android-2/how-to-access-localhost-on-android-over-wifi/
Did not install WAMP server. Skip that...
Created Port 80 rule inbound and it worked.








Friday, November 22, 2013

Using BCP utility

Bulk copy program bcp is still supported by SQL 2008 R2 and SQL 2012 Yeah!!!

SQL 2008 R2 http://technet.microsoft.com/en-us/library/ms162802(v=sql.105).aspx
The bcp 10.0 client is installed when you install Microsoft SQL Server 2008 R2 tools. If tools are installed for both SQL Server 2008 R2 and SQL Server 2005, depending on the value of the PATH environment variable, you might be using the earlier bcp client instead of the bcp 10.0 client. This environment variable defines the set of directories used by Windows to search for executable files. To discover which version you are using, run the bcp /v command at the Windows Command Prompt. For information about how to set the command path in the PATH environment variable, see Windows Help.

SQL 2012 http://technet.microsoft.com/en-us/library/ms162802.aspx
The bcp 11.0 client is installed when you install Microsoft SQL Server 2012 tools. If tools are installed for both SQL Server 2012 and an earlier version of SQL Server, depending on the value of the PATH environment variable, you might be using the earlier bcp client instead of the bcp 11.0 client. This environment variable defines the set of directories used by Windows to search for executable files. To discover which version you are using, run the bcp /v command at the Windows Command Prompt. For information about how to set the command path in the PATH environment variable, see Windows Help.

For exporting

bcp [database name].dbo.[table name] out  -n -S -U -P


For Import

bcp [database name].dbo.[table name] out  -n -S -U -P


case is important on arguments.  -n is very important. forces bcp to sql native format.  This is essential of you are exporting and importing data to tables to prevent truncating.

Example

Bcp [New410].dbo.tbCPTDx out tbCPTDx.bcp –n –SRISQA2008R2 –Usa –Psa